forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcors.ts
More file actions
30 lines (25 loc) · 710 Bytes
/
Copy pathcors.ts
File metadata and controls
30 lines (25 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { CorsOptions } from "cors";
import { AppError } from "../common/http/app-error";
import { env, securityConfig } from "./env";
export const corsOptions: CorsOptions = {
origin(origin, callback) {
if (!origin) {
callback(null, true);
return;
}
if (
env.NODE_ENV !== "production" &&
securityConfig.allowedOrigins.includes("*")
) {
callback(null, true);
return;
}
if (securityConfig.allowedOrigins.includes(origin)) {
callback(null, true);
return;
}
callback(new AppError(403, "Origin is not allowed by CORS policy"));
},
credentials: false,
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
};