Skip to content

Commit

Permalink
Implement CORS support
Browse files Browse the repository at this point in the history
Implemented CORS support per colyseus#2 (comment)
  • Loading branch information
403-Fruit authored May 18, 2021
1 parent 2e8234d commit c9e2d87
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ getNodeList().
catch(err => console.error(err));

const reqHandler = (req: http.IncomingMessage, res: http.ServerResponse) => {
if (req.method === 'OPTIONS') {
res.setHeader('access-control-allow-origin', '*');
res.setHeader('access-control-allow-credentials', 'true');
res.setHeader('access-control-allow-methods', '*');
res.setHeader('access-control-allow-headers', '*');
res.setHeader('access-control-max-age', 60 * 60 * 24 * 30);
res.statusCode = 200;
res.end();
return;
}

const proxy = getProxy(req.url!);

if (proxy) {
Expand Down

0 comments on commit c9e2d87

Please sign in to comment.