MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / createCorsOriginChecker

Function createCorsOriginChecker

backend/api/src/utils/cors.utils.ts:1–19  ·  view source on GitHub ↗
(allowedOrigins: string[])

Source from the content-addressed store, hash-verified

1export function createCorsOriginChecker(allowedOrigins: string[]) {
2 return (
3 origin: string | undefined,
4 callback: (err: Error | null, allow?: boolean) => void,
5 ) => {
6 // Allow requests with no origin (like mobile apps or Postman)
7 if (!origin) {
8 return callback(null, true);
9 }
10
11 // Check if origin matches any allowed pattern
12 if (isOriginAllowed(origin, allowedOrigins)) {
13 return callback(null, true);
14 }
15
16 // Reject other origins
17 callback(new Error('Not allowed by CORS'));
18 };
19}
20
21export function isOriginAllowed(
22 origin: string,

Callers 2

bootstrapFunction · 0.90
cors.utils.spec.tsFile · 0.90

Calls 1

isOriginAllowedFunction · 0.85

Tested by

no test coverage detected