-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcors.ts
More file actions
33 lines (31 loc) · 891 Bytes
/
cors.ts
File metadata and controls
33 lines (31 loc) · 891 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
31
32
33
import { envConstants } from 'core/constants';
import cors from 'cors';
const options: cors.CorsOptions = {
allowedHeaders: [
'Origin',
'X-Requested-With',
'Content-Type',
'Accept',
'X-Access-Token',
],
credentials: true,
methods: 'GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE',
// IMPORTANT LIMIT HERE YOUR CLIENT APPS DOMAINS
origin: (origin, callback) => {
const allowedOrigins = [
'http://localhost:8080',
'http://localhost:8081',
'https://codepaster.net',
'https://www.codepaster.net',
];
// Permitir peticiones sin origin (como Postman o curl)
if (!origin) return callback(null, true);
if (allowedOrigins.includes(origin)) {
return callback(null, true);
} else {
return callback(new Error('Not allowed by CORS'));
}
},
preflightContinue: false,
};
export const corsOptions = cors(options);