We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 40d3b2b commit f68e7d4Copy full SHA for f68e7d4
sample.env
@@ -5,3 +5,5 @@ DB_USER=c7f
5
DB_PASSWORD=c7f
6
DB_NAME=c7f
7
JWT_SECRET=secret
8
+ALLOW_CORS=true
9
+ALLOWED_ORIGINS=http://localhost:3001,http://locahost:5000
src/app.ts
@@ -13,9 +13,15 @@ const app = express();
13
app.set('PORT', process.env.PORT || 3000);
14
app.use(bodyParser.json());
15
16
-const { NODE_ENV } = process.env;
17
-if (NODE_ENV === 'dev') {
18
- app.use(cors());
+const { ALLOW_CORS, ALLOWED_ORIGINS } = process.env;
+if (ALLOW_CORS === 'true') {
+ const corsOptions = {
19
+ origin: ALLOWED_ORIGINS ? ALLOWED_ORIGINS.split(',') : '*',
20
+ };
21
+
22
+ app.use(cors(
23
+ corsOptions,
24
+ ));
25
}
26
27
app.use(appRoutes);
0 commit comments