greenlock-express.js/examples/http-proxy/server.js

45 lines
990 B
JavaScript
Raw Normal View History

2019-10-31 12:46:35 +00:00
"use strict";
function httpsWorker(glx) {
// we need the raw https server
var server = glx.httpsServer();
2019-11-01 10:12:40 +00:00
var proxy = require("http-proxy").createProxyServer({ xfwd: true });
2019-10-31 12:46:35 +00:00
// catches error events during proxying
proxy.on("error", function(err, req, res) {
console.error(err);
res.statusCode = 500;
res.end();
return;
});
2019-11-01 10:12:40 +00:00
// We'll proxy websockets too
2019-10-31 12:46:35 +00:00
server.on("upgrade", function(req, socket, head) {
proxy.ws(req, socket, head, {
ws: true,
2019-11-01 10:12:40 +00:00
target: "ws://localhost:3000"
2019-10-31 12:46:35 +00:00
});
});
// servers a node app that proxies requests to a localhost
glx.serveApp(function(req, res) {
proxy.web(req, res, {
target: "http://localhost:3000"
});
});
}
2019-11-01 10:12:40 +00:00
var pkg = require("../../package.json");
//require("greenlock-express")
require("../../")
.init(function getConfig() {
// Greenlock Config
return {
package: { name: "http-proxy-example", version: pkg.version },
maintainerEmail: "jon@example.com",
cluster: false
};
})
.serve(httpsWorker);