Fix CORS: lock to specific origins
This commit is contained in:
parent
1bf747bf68
commit
28e3ce922b
1 changed files with 5 additions and 1 deletions
|
|
@ -9,7 +9,11 @@ const PORT = process.env.PORT || 3001;
|
|||
app.use(express.json());
|
||||
app.use(express.static(path.join(__dirname, '../frontend/public')));
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
const allowedOrigins = ['http://localhost:3000', 'https://wardrobeai.scoble.me'];
|
||||
const origin = req.headers.origin;
|
||||
if (allowedOrigins.includes(origin)) {
|
||||
res.header('Access-Control-Allow-Origin', origin);
|
||||
}
|
||||
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||||
if (req.method === 'OPTIONS') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue