node es6 cors https proxy
const http = require('http'); | |
const https = require('https'); | |
const server = http.createServer(); | |
const host = 'example.com'; | |
server.on('request', (req, res) => { | |
// set cors on the response | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Accept-Language'); | |
// manipulate the headers for SSL | |
req.headers.host = host; | |
// form the options | |
var options = { | |
hostname: host, | |
port: 443, | |
path: req.url, | |
method: req.method, | |
headers: req.headers, | |
}; | |
var request = https.request(options, (response) => { | |
res.writeHead(response.statusCode, response.headers); | |
response.on('data', (d) => { res.write(d); }); | |
response.on('end', (d) => { res.end(); }); | |
}); | |
request.on('error', (e) => { console.error(e); }); | |
request.end(); | |
}); | |
server.listen(4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment