greenlock-express.js/examples/websockets.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-06-03 09:47:07 +00:00
"use strict";
2018-07-03 09:25:57 +00:00
////////////////////////
// Greenlock Setup //
////////////////////////
//var Greenlock = require('greenlock-express');
2019-06-03 09:47:07 +00:00
var Greenlock = require("../");
2018-07-03 09:25:57 +00:00
var greenlock = Greenlock.create({
2019-06-03 09:47:07 +00:00
// Let's Encrypt v2 is ACME draft 11
// Note: If at first you don't succeed, stop and switch to staging
// https://acme-staging-v02.api.letsencrypt.org/directory
server: "https://acme-v02.api.letsencrypt.org/directory",
version: "draft-11",
configDir: "~/.config/acme/",
app: require("./my-express-app.js"),
// You MUST change these to a valid email and domains
email: "john.doe@example.com",
approvedDomains: ["example.com", "www.example.com"],
agreeTos: true,
// Get notified of important updates and help me make greenlock better
communityMember: true,
telemetry: true
//, debug: true
2018-07-03 09:25:57 +00:00
});
2018-08-18 10:08:50 +00:00
var server = greenlock.listen(80, 443);
2018-07-03 09:25:57 +00:00
2019-06-03 09:47:07 +00:00
var WebSocket = require("ws");
2018-07-03 09:25:57 +00:00
var ws = new WebSocket.Server({ server: server });
2019-06-03 09:47:07 +00:00
ws.on("connection", function(ws, req) {
// inspect req.headers.authorization (or cookies) for session info
ws.send(
"[Secure Echo Server] Hello!\nAuth: '" +
(req.headers.authorization || "none") +
"'\n" +
"Cookie: '" +
(req.headers.cookie || "none") +
"'\n"
);
ws.on("message", function(data) {
ws.send(data);
});
2018-07-03 09:25:57 +00:00
});