1 parent 74f3c50 commit ed5ca17Copy full SHA for ed5ca17
1 file changed
apps/api/src/index.ts
@@ -12,11 +12,24 @@ const app = new Hono<{
12
Variables: AuthVars;
13
}>();
14
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
+
28
app.use("*", logger());
29
app.use(
30
"*",
31
cors({
- origin: (origin) => origin || "*",
32
+ origin: allowedCorsOrigin,
33
credentials: true,
34
}),
35
);
0 commit comments