Merge pull request #3 from AverageMarcus/fix/options

Always return 200 for OPTIONS
This commit is contained in:
Marcus Noble 2018-11-14 15:44:19 +00:00 committed by GitHub
commit ae887c6cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,14 @@ http.createServer((req, response) => {
let remoteURL = url.parse(req.url.substring(1)); let remoteURL = url.parse(req.url.substring(1));
if(!remoteURL.hostname || remoteURL.hostname === 'localhost') return response.end(); if(!remoteURL.hostname || remoteURL.hostname === 'localhost') return response.end();
if(req.method === 'OPTIONS') {
response.writeHead(200, {
'access-control-allow-origin': req.headers.origin || '*',
'access-control-allow-headers': 'Origin, X-Requested-With, Content-Type, Accept, authorization'
});
return response.end();
}
for(let key in req.headers) { for(let key in req.headers) {
if(key.match(/host|cookie/ig)){ if(key.match(/host|cookie/ig)){
delete req.headers[key]; delete req.headers[key];