node-reverse-proxy
This package allows multiple web servers to run on the same server by mapping internal ports to external domain/subdomain (see below axample in routes),
👉 To install this package run npm i ShawnCockburn/node-reverse-proxy
Example route object:
{
"routes":{
"shawncockburn_co_uk": {
"host": "shawncockburn.co.uk",
"target": "http://localhost:8000"
},
"blog_shawncockburn_co_uk": {
"host": "blog.shawncockburn.co.uk",
"target": "http://localhost:4001"
}
}
}
const config = require("./config.json");
const fs = require('fs');
const nodeReverseProxyServer = require("node-reverse-proxy");
const key = fs.readFileSync('./ssl/private_key.key', 'utf8');
const cert = fs.readFileSync('./ssl/ssl_certificate.cer', 'utf8');
const ca = fs.readFileSync('./ssl/ssl_intermediate_certificate.cer', 'utf8');
const serverObject = nodeReverseProxyServer({
routes: Object.values(config.routes),
sslConfig: {
key: key,
cert: cert,
ca: ca
},
forceSSL: true
});
//hide express
serverObject.app.disable('x-powered-by');
nodeReverseProxyServer.Server(serverObject);
sudo node index.js
Feel free to drop a PR if you have any improvements/features