Extract backend runtime configuration
This commit is contained in:
13
backend/config/cors.js
Normal file
13
backend/config/cors.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const cors = require('cors');
|
||||
|
||||
const createCorsMiddleware = ({ allowedOrigins, isProduction }) => cors({
|
||||
origin: (origin, callback) => {
|
||||
if (!origin || !isProduction || allowedOrigins.includes(origin)) {
|
||||
return callback(null, true);
|
||||
}
|
||||
return callback(new Error('Origem não permitida pelo CORS.'));
|
||||
},
|
||||
credentials: true
|
||||
});
|
||||
|
||||
module.exports = { createCorsMiddleware };
|
||||
Reference in New Issue
Block a user