greenlock-express.js/examples/cluster/server.js

37 lines
933 B
JavaScript
Raw Normal View History

2019-11-01 10:12:40 +00:00
"use strict";
//require("greenlock-express")
require("../../")
2020-01-11 00:51:25 +00:00
.init({
packageRoot: __dirname,
configDir: "./greenlock.d",
2019-11-01 10:12:40 +00:00
2020-01-11 00:51:25 +00:00
maintainerEmail: "jon@example.com",
2019-11-01 10:12:40 +00:00
2020-01-11 00:51:25 +00:00
// When you're ready to go full cloud scale, you just change this to true:
// Note: in cluster you CANNOT use in-memory state (see below)
cluster: true,
2019-11-01 10:12:40 +00:00
2020-01-11 00:51:25 +00:00
// This will default to the number of workers being equal to
// n-1 cpus, with a minimum of 2
workers: 4
2019-11-01 21:14:07 +00:00
})
2020-01-11 00:51:25 +00:00
.ready(httpsWorker);
2019-11-01 10:12:40 +00:00
function httpsWorker(glx) {
2019-11-01 21:14:07 +00:00
// WRONG
// This won't work like you
// think because EACH worker
// has ITS OWN `count`.
var count = 0;
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +00:00
var app = function(req, res) {
res.end("Hello... how many times now? Oh, " + count + " times");
count += 1;
};
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +00:00
// Serves on 80 and 443... for each worker
// Get's SSL certificates magically!
glx.serveApp(app);
2019-11-01 10:12:40 +00:00
}