Handle authenticated endpoints
This commit is contained in:
parent
e4c691c9c6
commit
4574e8f4f2
19
index.js
19
index.js
@ -24,17 +24,28 @@ http.createServer((req, response) => {
|
|||||||
url: remoteURL,
|
url: remoteURL,
|
||||||
followAllRedirects: true,
|
followAllRedirects: true,
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers: req.headers
|
headers: req.headers,
|
||||||
|
gzip: true
|
||||||
};
|
};
|
||||||
|
|
||||||
if(req.method !== 'HEAD') {
|
if(req.method !== 'HEAD') {
|
||||||
config.body = req;
|
config.body = req;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
|
|
||||||
request(config)
|
request(config)
|
||||||
|
.on('response', res => {
|
||||||
|
res.headers['access-control-allow-origin'] = req.headers.origin || '*';
|
||||||
|
res.headers['access-control-allow-headers'] = 'Origin, X-Requested-With, Content-Type, Accept, authorization';
|
||||||
|
delete res.headers['access-control-allow-credentials'];
|
||||||
|
delete res.headers['access-control-allow-methods'];
|
||||||
|
delete res.headers['content-encoding'];
|
||||||
|
delete res.headers['content-length'];
|
||||||
|
response.writeHead(res.statusCode, res.headers);
|
||||||
|
})
|
||||||
|
.on('data', function(data) {
|
||||||
|
response.write(data);
|
||||||
|
})
|
||||||
.on('error', () => response.end())
|
.on('error', () => response.end())
|
||||||
.pipe(response, {end:true});
|
.on('end', () => response.end());
|
||||||
|
|
||||||
}).listen(PORT);
|
}).listen(PORT);
|
||||||
|
Loading…
Reference in New Issue
Block a user