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

39 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2019-11-01 10:12:40 +00:00
"use strict";
// The WRONG way:
//var http = require('http');
2020-04-26 23:13:02 +00:00
//var httpServer = http.createServer(redirectToHttps);
2019-11-01 10:12:40 +00:00
//
// Why is that wrong?
// Greenlock needs to change some low-level http and https options.
// Use glx.httpServer(redirectToHttps) instead.
2020-01-11 00:51:25 +00:00
//require("greenlock-express")
require("../../")
.init({
packageRoot: __dirname,
configDir: "./greenlock.d",
maintainerEmail: "jon@example.com",
cluster: false
})
.ready(httpsWorker);
2019-11-01 10:12:40 +00:00
function httpsWorker(glx) {
2019-11-01 21:14:07 +00:00
//
// HTTP can only be used for ACME HTTP-01 Challenges
// (and it is not required for DNS-01 challenges)
//
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +00:00
// Get the raw http server:
var httpServer = glx.httpServer(function(req, res) {
res.statusCode = 301;
res.setHeader("Location", "https://" + req.headers.host + req.path);
res.end("Insecure connections are not allowed. Redirecting...");
});
2019-11-01 10:12:40 +00:00
2019-11-01 21:14:07 +00:00
httpServer.listen(80, "0.0.0.0", function() {
console.info("Listening on ", httpServer.address());
});
2019-11-01 10:12:40 +00:00
}