Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/proxy/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,37 @@ describe("Proxy Handler", () => {
}
});

it("returns 404 for an environment root that names no project", async () => {
// staging.veryfront.com parses as an environment root: a veryfront domain
// with slug null. It used to be forwarded with x-project-slug: "", which
// the runtime answers 502 "Missing project context" — a config gap
// reported as an upstream failure. It is the same condition a custom
// domain answers 404 for.
const { server, port } = createMockServer((req: Request) => {
const { pathname } = new URL(req.url);
if (pathname === "/auth/token") return createTokenResponse();
return createNotFoundResponse();
});

try {
const handler = createHandler(port);

for (const host of ["staging.veryfront.com", "preview.veryfront.com"]) {
const ctx = await handler.processRequest(
new Request(`http://${host}/page`, { headers: { host } }),
);

assertEquals(ctx.projectSlug, undefined);
assertEquals(ctx.error?.status, 404);
assertEquals(ctx.error?.message, `No project configured for domain: ${host}`);
}
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved

await handler.close();
} finally {
await server.shutdown();
}
});

it("returns 404 error when custom domain not found", async () => {
const { server, port } = createMockServer((req: Request) => {
const { pathname } = new URL(req.url);
Expand Down
21 changes: 10 additions & 11 deletions src/proxy/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,17 +815,16 @@ export function createProxyHandler(options: ProxyHandlerOptions) {
}, logger);

if (!projectSlug && parsedDomain.isVeryfrontDomain) {
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
return {
token: undefined,
projectSlug: undefined,
projectId: undefined,
environment: "preview",
contentSourceId: "no-project",
localPath: undefined,
host,
parsedDomain,
isLocalProject: false,
};
// An environment root (staging.veryfront.com) or a bare dev domain names no
// project. Forwarding it sends x-project-slug: "" to the runtime, which
// answers 502 "Missing project context" — a config gap reported as an
// upstream failure. A custom domain in the same state already answers 404,
// so answer the same way here.
logger?.info("No project for veryfront domain", { host });
return createProxyErrorContext(base, {
status: 404,
message: `No project configured for domain: ${host}`,
});
}

const localPath = projectSlug ? await localProjectResolver.find(projectSlug) : undefined;
Expand Down
Loading