production is a static build behind nginx, not a process
The site's own build script says it outright: "The public site is not served by Bun in production — it is a directory of files behind nginx. Output: dist/." So production has no port, nothing to restart, and nothing that can crash at three in the morning. It is built or stale, and served or not served. Showing it as a pm2 process was showing something that does not exist, and its Start button could only ever have failed. It now has Build, Serve and Stop, and the two states are reported separately — a build can succeed while nothing serves it, and a container can serve a directory built weeks ago. They fail independently and are fixed differently. The container exists because nginx could not see the files. NPM mounts only its own /data and /etc/letsencrypt, and there is no other nginx on the box. The alternatives were putting site files inside NPM's own volume, or editing NPM's compose and restarting it — which takes every site on this machine down for a moment. So: one nginx:alpine, dist mounted READ-ONLY, on NPM's own network with NO published port. NPM reaches it by name, and nothing about the site is exposed except through the proxy. Recreated rather than restarted, for the same reason pm2 is: a container keeps the mounts it was created with, so a root location changed here would be saved, displayed, and still serving the old directory. Domains follows. Production's forward target is a container NAME, not the docker gateway that reaches a host process — and matching what already points at it uses the full target rather than the port, since every other site behind this NPM on port 80 would otherwise be listed as fofos's. The compiler found the dead branches this left in startServer once production could no longer reach it. Removed rather than left to read as though the case were still possible. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+48
-6
@@ -73,6 +73,14 @@ export const ProxiesBlock = ({ servers }: { servers: Server[] }) => {
|
||||
clientRef.current = client;
|
||||
|
||||
const [hosts, setHosts] = useState<Host[] | null>(null);
|
||||
/*
|
||||
Production is not a port on this machine.
|
||||
|
||||
It is a container on the same docker network as NPM, so the forward target is a NAME — `fofos-web:80`
|
||||
— and the gateway address that reaches a host process would reach nothing. Read here rather than
|
||||
passed down, because the shape of production's target is this block's business.
|
||||
*/
|
||||
const [staticTarget, setStaticTarget] = useState<{ host: string; port: number } | null>(null);
|
||||
const [unavailable, setUnavailable] = useState(false);
|
||||
const [domains, setDomains] = useState<Record<string, string>>({});
|
||||
const [forwardHost, setForwardHost] = useState('');
|
||||
@@ -89,6 +97,11 @@ export const ProxiesBlock = ({ servers }: { servers: Server[] }) => {
|
||||
for (const host of found) counts.set(host.forward_host, (counts.get(host.forward_host) ?? 0) + 1);
|
||||
const common = [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
||||
if (common) setForwardHost((typed) => typed || common);
|
||||
|
||||
const web = await clientRef.current
|
||||
.get<{ container: { name: string } }>('/fofos-admin/_config/static')
|
||||
.catch(() => null);
|
||||
if (web?.container?.name) setStaticTarget({ host: web.container.name, port: 80 });
|
||||
} catch {
|
||||
// Not installed, not running, or not permitted. Reported as absent rather than as an error: this
|
||||
// block is an integration with another plugin, and its absence is a fact rather than a fault.
|
||||
@@ -108,14 +121,20 @@ export const ProxiesBlock = ({ servers }: { servers: Server[] }) => {
|
||||
setFailed(false);
|
||||
setOutput(null);
|
||||
try {
|
||||
// Production goes to the container by name; development to the host, at its port.
|
||||
const target =
|
||||
server.name === 'production' && staticTarget
|
||||
? { host: staticTarget.host, port: staticTarget.port }
|
||||
: { host: forwardHost.trim(), port: server.port! };
|
||||
|
||||
await clientRef.current.post('/proxy-manager/npm/nginx/proxy-hosts', {
|
||||
...NEW_HOST,
|
||||
domain_names: [domain],
|
||||
forward_scheme: 'http',
|
||||
forward_host: forwardHost.trim(),
|
||||
forward_port: server.port,
|
||||
forward_host: target.host,
|
||||
forward_port: target.port,
|
||||
});
|
||||
setOutput(`${domain} → ${forwardHost.trim()}:${server.port}`);
|
||||
setOutput(`${domain} → ${target.host}:${target.port}`);
|
||||
setDomains((current) => ({ ...current, [server.name]: '' }));
|
||||
await load();
|
||||
} catch (failure) {
|
||||
@@ -246,13 +265,33 @@ export const ProxiesBlock = ({ servers }: { servers: Server[] }) => {
|
||||
const row = (server: Server) => {
|
||||
const label = server.name === 'development' ? 'Development' : 'Production';
|
||||
// Everything NPM already points at this server's port, whoever made it.
|
||||
const mine = (hosts ?? []).filter((host) => host.forward_port === server.port);
|
||||
/*
|
||||
What already points at this server.
|
||||
|
||||
Matched on the FULL target rather than the port alone: production forwards to a container on port
|
||||
80, and every other site behind this NPM that happens to use port 80 would otherwise be listed here
|
||||
as though it belonged to fofos.
|
||||
*/
|
||||
const mine = (hosts ?? []).filter((host) =>
|
||||
server.name === 'production' && staticTarget
|
||||
? host.forward_host === staticTarget.host && host.forward_port === staticTarget.port
|
||||
: host.forward_port === server.port && server.port !== null,
|
||||
);
|
||||
|
||||
return (
|
||||
<div key={server.name} className="flex flex-col gap-2 border-t border-border pt-3 first:border-0 first:pt-0">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{label}
|
||||
{server.port ? <span className="font-mono"> · port {server.port}</span> : ' · no port set'}
|
||||
<span className="font-mono">
|
||||
{' · '}
|
||||
{server.name === 'production'
|
||||
? staticTarget
|
||||
? `${staticTarget.host}:${staticTarget.port}`
|
||||
: 'static, no server yet'
|
||||
: server.port
|
||||
? `port ${server.port}`
|
||||
: 'no port set'}
|
||||
</span>
|
||||
</p>
|
||||
|
||||
{mine.map((host) => (
|
||||
@@ -325,7 +364,10 @@ export const ProxiesBlock = ({ servers }: { servers: Server[] }) => {
|
||||
};
|
||||
|
||||
// Nothing left to point anywhere: every server already has a domain.
|
||||
const anythingToCreate = servers.some((server) => !(hosts ?? []).some((host) => host.forward_port === server.port));
|
||||
// Development only: production's target is a container name, not the gateway address this field holds.
|
||||
const anythingToCreate = servers.some(
|
||||
(server) => server.name === 'development' && !(hosts ?? []).some((host) => host.forward_port === server.port),
|
||||
);
|
||||
|
||||
return (
|
||||
<Block icon={Globe} title="Domains" hint="Which addresses reach the site, through Nginx Proxy Manager.">
|
||||
|
||||
Reference in New Issue
Block a user