feat(socketio): get cors allowed origins from env file
This commit is contained in:
parent
3c4829a355
commit
b261cee228
1
backend/services/socketio/.gitignore
vendored
1
backend/services/socketio/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.env.local
|
||||||
1089
backend/services/socketio/package-lock.json
generated
1089
backend/services/socketio/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
|
@ -13,6 +13,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@koa/cors": "^4.0.0",
|
"@koa/cors": "^4.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^16.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"koa": "^2.14.2",
|
"koa": "^2.14.2",
|
||||||
"socket.io": "^4.6.2"
|
"socket.io": "^4.6.2"
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,24 @@
|
||||||
|
const dotenv = require('dotenv')
|
||||||
|
dotenv.config();
|
||||||
|
dotenv.config({ path: `.env.local`, override: true });
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 5000;
|
const PORT = 5000;
|
||||||
|
|
||||||
const http = require('http').Server(app);
|
const http = require('http').Server(app);
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
|
var allowedOrigins;
|
||||||
|
let allowedOriginsFromEnv = process.env.CORS_ALLOWED_ORIGINS.split(',')
|
||||||
|
if (allowedOriginsFromEnv.length > 1) {
|
||||||
|
allowedOrigins = allowedOriginsFromEnv
|
||||||
|
}else{
|
||||||
|
allowedOrigins = "*"
|
||||||
|
}
|
||||||
|
console.log("allowedOrigins:",allowedOrigins)
|
||||||
|
|
||||||
const io = require('socket.io')(http, {
|
const io = require('socket.io')(http, {
|
||||||
cors: {
|
cors: {
|
||||||
origin: "http://localhost:3000"
|
origin: allowedOrigins
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user