expanding CORS options and enabling explicit preflight response
This commit is contained in:
parent
3044ad6783
commit
2a7b525b83
@ -41,7 +41,16 @@ app.use(cors({
|
|||||||
credentials: true
|
credentials: true
|
||||||
}));
|
}));
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*');
|
||||||
|
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
||||||
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||||
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||||
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
||||||
|
|
||||||
|
if (req.method === 'OPTIONS') {
|
||||||
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user