Skip to content

Commit ed5ca17

Browse files
committed
fix: allow credentialed api cors
1 parent 74f3c50 commit ed5ca17

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

apps/api/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ const app = new Hono<{
1212
Variables: AuthVars;
1313
}>();
1414

15+
function allowedCorsOrigin(origin: string | undefined) {
16+
const webBaseUrl = process.env.APP_WEB_BASE_URL || "http://localhost:5173";
17+
const allowed = new Set([
18+
webBaseUrl.replace(/\/+$/g, ""),
19+
"http://localhost:5173",
20+
"http://127.0.0.1:5173",
21+
"https://next.cnodejs.org",
22+
"https://cnodejs.org",
23+
"https://www.cnodejs.org",
24+
]);
25+
return origin && allowed.has(origin) ? origin : webBaseUrl;
26+
}
27+
1528
app.use("*", logger());
1629
app.use(
1730
"*",
1831
cors({
19-
origin: (origin) => origin || "*",
32+
origin: allowedCorsOrigin,
2033
credentials: true,
2134
}),
2235
);

0 commit comments

Comments
 (0)