add cors allow list
This commit is contained in:
parent
c94b7be5fb
commit
f763e733f0
2 changed files with 14 additions and 2 deletions
|
@ -2,7 +2,13 @@ module.exports = {
|
|||
ports: {
|
||||
mainServerPort: 3005,
|
||||
},
|
||||
address: 'b.hippoz.xyz',
|
||||
address: 'localhost',
|
||||
//restrictions: {
|
||||
// signup: {
|
||||
// specialCode: ''
|
||||
// }
|
||||
//},
|
||||
corsAllowList: [ 'localhost' ],
|
||||
mongoUrl: 'mongodb://192.168.0.105:27017/app',
|
||||
bcryptRounds: 10,
|
||||
roleMap: {
|
||||
|
|
8
index.js
8
index.js
|
@ -18,7 +18,13 @@ app.use(express.urlencoded({ extended: false }));
|
|||
app.use(express.json());
|
||||
app.use(cookieParser());
|
||||
app.use(cors({
|
||||
origin: config.isHttps ? `https://${config.address}` : `http://${config.address}`,
|
||||
origin: function (origin, callback) {
|
||||
if (config.corsAllowList.indexOf(origin) !== -1) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
},
|
||||
credentials: true,
|
||||
optionsSuccessStatus: 200
|
||||
}));
|
||||
|
|
Reference in a new issue