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

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-01 10:12:40 +00:00
"use strict";
var pkg = require("../../package.json");
//require("greenlock-express")
require("../../")
2019-11-01 21:14:07 +00:00
.init(function getConfig() {
// Greenlock Config
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +00:00
return {
package: { name: "websocket-example", version: pkg.version },
maintainerEmail: "jon@example.com",
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +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
2019-11-01 21:14:07 +00:00
// This will default to the number of workers being equal to
// n-1 cpus, with a minimum of 2
workers: 4
};
})
.serve(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
}