Skip to content

Commit d6f0a90

Browse files
committed
fix: more cors updates
multi-origin requires callback not a list
1 parent a870c73 commit d6f0a90

File tree

1 file changed

+9
-1
lines changed
  • packages/auth-server-api/src

1 file changed

+9
-1
lines changed

packages/auth-server-api/src/app.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ const app = express();
1111
app.use(express.json());
1212

1313
// CORS configuration
14-
const corsOrigins = env.CORS_ORIGINS.split(",").map((origin) => origin.trim());
14+
const corsOrigins = (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => {
15+
const allowlist = env.CORS_ORIGINS.split(",").map((origin) => origin.trim());
16+
if (!origin || allowlist.indexOf(origin) !== -1) {
17+
callback(null, true);
18+
} else {
19+
callback(new Error("Not allowed by CORS"));
20+
}
21+
};
22+
1523
app.use(
1624
cors({
1725
origin: corsOrigins,

0 commit comments

Comments
 (0)