refactor: separate handlers, allow multiple devices to respond
This commit is contained in:
parent
176e1c06a3
commit
50a4d9360a
|
@ -3,12 +3,18 @@
|
|||
var http = require('http');
|
||||
var tls = require('tls');
|
||||
var packerStream = require('tunnel-packer').Stream;
|
||||
var redirectHttps = require('redirect-https')();
|
||||
|
||||
module.exports.create = function (program) {
|
||||
program.httpServer = http.createServer(function (req, res) {
|
||||
console.log('req.socket.encrypted', req.socket.encrypted);
|
||||
res.end("Look! I can do a thing!");
|
||||
});
|
||||
|
||||
program.httpInsecureServer = http.createServer(function (req, res) {
|
||||
res.setHeader('Connection', 'close');
|
||||
redirectHttps(req, res);
|
||||
});
|
||||
program.httpTunnelServer = http.createServer(function (req, res) {
|
||||
console.log('req.socket.encrypted', req.socket.encrypted);
|
||||
res.end('Hello, World!');
|
||||
|
|
|
@ -42,13 +42,15 @@ Devices.exist = function (store, servername) {
|
|||
};
|
||||
Devices.next = function (store, servername) {
|
||||
var devices = Devices.list(store, servername);
|
||||
var device;
|
||||
|
||||
if (devices._index >= devices.length) {
|
||||
devices._index = 0;
|
||||
}
|
||||
device = devices[devices._index || 0];
|
||||
devices._index = (devices._index || 0) + 1;
|
||||
|
||||
return devices[devices._index];
|
||||
return device;
|
||||
};
|
||||
|
||||
module.exports.store = { Devices: Devices };
|
||||
|
@ -337,6 +339,8 @@ module.exports.create = function (copts) {
|
|||
console.log('servername', servername);
|
||||
if (/HTTP\//i.test(str)) {
|
||||
service = 'http';
|
||||
// TODO disallow http entirely
|
||||
// /^\/\.well-known\/acme-challenge\//.test(str)
|
||||
if (/well-known/.test(str)) {
|
||||
// HTTP
|
||||
if (Devices.exist(deviceLists, servername)) {
|
||||
|
|
Loading…
Reference in New Issue