tlsconfigguide icon indicating copy to clipboard operation
tlsconfigguide copied to clipboard

http-master and http-proxy templates for Node.js

Open trusktr opened this issue 7 years ago • 0 comments

It'd be nice to add templates for http-master and http-proxy. They are Apache/Nginx-like tools for Node.js (perhaps easier to work with, it's just JS!).

For example, the config for http-proxy might look like

// -- ####### HTTPS PROXY SERVER #######
var fs = require("fs")

var files = [
    "/etc/letsencrypt/live/example.com/chain.pem",
]

var caChain = []

files.forEach(function(file) {
    caChain.push(fs.readFileSync(file))
})

var httpsOptions = {
    https: {
        ca: caChain,
        key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem', 'utf8'),
        cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem', 'utf8')
    },
    router: {
        'example.com': '127.0.0.1:5678', // map a domain to a local service
        // ... etc ...
    }
    // ... other options ...
}

var httpsProxyServer = httpProxy.createServer(httpsOptions, function(request, response, proxy) {
    // do whatever you need with the request and response objects, f.e. redirect certain paths to another domain, etc.
})

httpsProxyServer.listen(443) // listen on the standard HTTPS port.

trusktr avatar Dec 01 '18 23:12 trusktr