Skip to content

Commit

Permalink
Add Access-Control header for CORS (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaisueper authored and devongovett committed Feb 14, 2018
1 parent 9616277 commit 1c761fd
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,27 @@ serveStatic.mime.define({
'application/wasm': ['wasm']
});

function setHeaders(res) {
enableCors(res);
}

function enableCors(res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Methods',
'GET, HEAD, PUT, PATCH, POST, DELETE'
);
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Content-Type'
);
}

function middleware(bundler) {
const serve = serveStatic(bundler.options.outDir, {index: false});
const serve = serveStatic(bundler.options.outDir, {
index: false,
setHeaders: setHeaders
});

return function(req, res, next) {
// Wait for the bundler to finish bundling if needed
Expand Down

0 comments on commit 1c761fd

Please sign in to comment.