fix(server): include cors headers on 404s

This commit is contained in:
Brendan Allan
2026-07-17 06:57:13 +00:00
parent 08ea08e830
commit efaeda00a1
2 changed files with 61 additions and 3 deletions
@@ -82,6 +82,35 @@ describe("HttpApi CORS", () => {
}),
)
it.live("adds CORS headers to not found responses", () =>
Effect.gen(function* () {
const handler = HttpRouter.toWebHandler(
HttpApiApp.createRoutes().pipe(
Layer.provide(
ConfigProvider.layer(
ConfigProvider.fromUnknown({
OPENCODE_DISABLE_EMBEDDED_WEB_UI: "true",
}),
),
),
),
{ disableLogger: true },
).handler
const response = yield* Effect.promise(() =>
handler(
new Request(new URL("/api/health", "http://localhost"), {
method: "POST",
headers: { origin: "https://app.opencode.ai" },
}),
HttpApiApp.context,
),
)
expect(response.status).toBe(404)
expect(response.headers.get("access-control-allow-origin")).toBe("https://app.opencode.ai")
}),
)
it.live("uses custom CORS origins passed to the server", () =>
Effect.gen(function* () {
const listener = yield* Effect.acquireRelease(