How can I start a proxy server by node.js for HTTPS

Viewed 23

what I want to implement:

I set a browser proxy by SwitchyOmega and start a proxy server by node in 127.0.0.1:9999.

When I visit https://www.google.com, I want to get the client request in my proxy server, then the proxy server visit https://www.google.com, and then I can modify the response before return it to client.

I've signed a cert with a SAN of 127.0.0.1 by openssl and it was trusted by my system. when I visit https://127.0.0.1:9999 straigtly, the cert is valid in chrome and I can get the response.

but when I start the switchyomega and visit https://www.google.com the request's status is 'failed'。

my code:

const https = require('https')
const fs = require('fs')

const option = {
    key: fs.readFileSync('./key1.pem'), 
    cert: fs.readFileSync('./cert1.pem') 
};

https.createServer(option, (req, res) => {
    res.end('res be modified')
})
.listen(9999, () => {
    console.log('proxy server is running at https://127.0.0.1:9999')
})

my switchyomega have set a proxy mode: https 127.0.0.1 9999

0 Answers
Related