Skip to content

Commit dca2d35

Browse files
authored
Merge pull request #26 from Acode-Foundation/fix-cors-header
fix(cors): handle preflight requests and improve CORS headers
2 parents 9c52099 + c6c330c commit dca2d35

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ main();
2626
async function main() {
2727
await setAuth();
2828

29-
// allow origin https://localhost
3029
app.use((_req, res, next) => {
3130
res.header('Access-Control-Allow-Origin', 'https://localhost');
3231
res.header('Access-Control-Allow-Headers', 'Content-Type, x-auth-token');
32+
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
33+
if (_req.method === 'OPTIONS') {
34+
res.sendStatus(204);
35+
return;
36+
}
3337
next();
3438
});
3539

0 commit comments

Comments
 (0)