Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trusktr opened this issue Dec 1, 2018 · 0 comments
Open

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

trusktr opened this issue Dec 1, 2018 · 0 comments

Comments

@trusktr
Copy link

trusktr commented Dec 1, 2018

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant