Serve the resource from the right place

This commit is contained in:
Owen
2026-05-13 18:01:36 -07:00
parent 2a33256d17
commit 2250fcd177

View File

@@ -1153,7 +1153,7 @@ export async function getTraefikConfig(
middlewares: routerMiddlewares, middlewares: routerMiddlewares,
service: bgServiceName, service: bgServiceName,
rule: bgRule, rule: bgRule,
priority: 110, // higher than 105 (UI router) to match /gateway/* first priority: 110, // highest - websocket path takes precedence
...(bgResource.ssl ? { tls } : {}) ...(bgResource.ssl ? { tls } : {})
}; };
@@ -1164,37 +1164,59 @@ export async function getTraefikConfig(
}; };
} }
// UI router: serve the browser gateway pages from the internal pangolin instance // UI: serve the browser gateway page from the internal pangolin instance.
// Covers /{type} paths for each configured type plus Next.js assets // The primary type is used for the path rewrite (e.g. /rdp), mirroring
// how the maintenance page rewrites everything to /maintenance-screen.
const primaryType = typeMap.keys().next().value as string;
const internalHost = config.getRawConfig().server.internal_hostname; const internalHost = config.getRawConfig().server.internal_hostname;
const internalPort = config.getRawConfig().server.next_port; const internalPort = config.getRawConfig().server.next_port;
const uiRewriteMiddlewareName = `bg-r${bgResource.resourceId}-ui-rewrite`;
const entrypoint = bgResource.ssl
? config.getRawConfig().traefik.https_entrypoint
: config.getRawConfig().traefik.http_entrypoint;
const typePaths = Array.from(typeMap.keys()) if (!config_output.http.middlewares) {
.map((t) => `PathPrefix(\`/${t}\`)`) config_output.http.middlewares = {};
.join(" || "); }
const uiRule = `${hostRule} && (${typePaths} || PathPrefix(\`/_next\`) || PathRegexp(\`^/__nextjs*\`))`;
config_output.http.middlewares![uiRewriteMiddlewareName] = {
replacePathRegex: {
regex: "^/(.*)",
replacement: `/${primaryType}`
}
};
config_output.http.services![bgUiServiceName] = { config_output.http.services![bgUiServiceName] = {
loadBalancer: { loadBalancer: {
servers: [ servers: [
{ {
url: `http://${internalHost}:${internalPort}` // url: `http://${internalHost}:${internalPort}`
url: `https://owen-devel.hostlocal.app`
} }
] ]
} }
}; };
// Assets router at higher priority so /_next files load without rewrite
config_output.http.routers![
`bg-r${bgResource.resourceId}-assets-router`
] = {
entryPoints: [entrypoint],
middlewares: routerMiddlewares,
service: bgUiServiceName,
rule: `${hostRule} && (PathPrefix(\`/_next\`) || PathRegexp(\`^/__nextjs*\`))`,
priority: 101,
...(bgResource.ssl ? { tls } : {})
};
// Catch-all router rewrites everything on the domain to /{primaryType}
config_output.http.routers![`bg-r${bgResource.resourceId}-ui-router`] = config_output.http.routers![`bg-r${bgResource.resourceId}-ui-router`] =
{ {
entryPoints: [ entryPoints: [entrypoint],
bgResource.ssl middlewares: [...routerMiddlewares, uiRewriteMiddlewareName],
? config.getRawConfig().traefik.https_entrypoint
: config.getRawConfig().traefik.http_entrypoint
],
middlewares: routerMiddlewares,
service: bgUiServiceName, service: bgUiServiceName,
rule: uiRule, rule: hostRule,
priority: 105, priority: 100,
...(bgResource.ssl ? { tls } : {}) ...(bgResource.ssl ? { tls } : {})
}; };
} }