2019-06-03 09:47:07 +00:00
|
|
|
"use strict";
|
2018-05-15 18:34:32 +00:00
|
|
|
|
|
|
|
//var Greenlock = require('greenlock-express')
|
2019-06-03 09:47:07 +00:00
|
|
|
var Greenlock = require("../");
|
2018-05-15 18:34:32 +00:00
|
|
|
|
|
|
|
var greenlock = Greenlock.create({
|
2019-06-03 09:47:07 +00:00
|
|
|
// Let's Encrypt v2 is ACME draft 11
|
|
|
|
version: "draft-11",
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
server: "https://acme-v02.api.letsencrypt.org/directory",
|
|
|
|
// Note: If at first you don't succeed, stop and switch to staging
|
|
|
|
// https://acme-staging-v02.api.letsencrypt.org/directory
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
// You MUST change this to a valid email address
|
|
|
|
email: "jon@example.com",
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
// You MUST NOT build clients that accept the ToS without asking the user
|
|
|
|
agreeTos: true,
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
// You MUST change these to valid domains
|
|
|
|
// NOTE: all domains will validated and listed on the certificate
|
|
|
|
approvedDomains: ["example.com", "www.example.com"],
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
// You MUST have access to write to directory where certs are saved
|
|
|
|
// ex: /home/foouser/acme/etc
|
|
|
|
configDir: "~/.config/acme/",
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
// Get notified of important updates and help me make greenlock better
|
|
|
|
communityMember: true
|
2018-05-15 18:34:32 +00:00
|
|
|
|
2019-06-03 09:47:07 +00:00
|
|
|
//, debug: true
|
2018-05-15 18:34:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
// http-01 Challenges //
|
|
|
|
////////////////////////
|
|
|
|
|
|
|
|
// http-01 challenge happens over http/1.1, not http2
|
2019-06-03 09:47:07 +00:00
|
|
|
var redirectHttps = require("redirect-https")();
|
2018-05-15 18:34:32 +00:00
|
|
|
var acmeChallengeHandler = greenlock.middleware(redirectHttps);
|
2019-06-03 09:47:07 +00:00
|
|
|
require("http")
|
|
|
|
.createServer(acmeChallengeHandler)
|
|
|
|
.listen(80, function() {
|
|
|
|
console.log("Listening for ACME http-01 challenges on", this.address());
|
|
|
|
});
|
2018-05-15 18:34:32 +00:00
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
// node.js' http2 api //
|
|
|
|
////////////////////////
|
|
|
|
|
|
|
|
// http2 is a new API with which you would use hapi or koa, not express
|
2019-06-03 09:47:07 +00:00
|
|
|
var server = require("http2").createSecureServer(greenlock.tlsOptions);
|
|
|
|
server.on("error", function(err) {
|
|
|
|
console.error(err);
|
2018-05-15 18:34:32 +00:00
|
|
|
});
|
2018-08-18 10:08:50 +00:00
|
|
|
// WARNING: Because the middleware don't handle this API style,
|
|
|
|
// the Host headers are unmodified and potentially dangerous
|
|
|
|
// (ex: Host: Robert'); DROP TABLE Students;)
|
2019-06-03 09:47:07 +00:00
|
|
|
server.on("stream", function(stream, headers) {
|
|
|
|
console.log(headers);
|
|
|
|
stream.respond({
|
|
|
|
"content-type": "text/html",
|
|
|
|
":status": 200
|
|
|
|
});
|
|
|
|
stream.end("Hello, HTTP2 World!");
|
2018-05-15 18:34:32 +00:00
|
|
|
});
|
2019-06-03 09:47:07 +00:00
|
|
|
server.on("listening", function() {
|
|
|
|
console.log("Listening for http2 requests on", this.address());
|
2018-05-15 18:34:32 +00:00
|
|
|
});
|
|
|
|
server.listen(443);
|