-
-
Notifications
You must be signed in to change notification settings - Fork 935
/
server.js
40 lines (31 loc) · 885 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const http = require('http');
const https = require('https');
const pify = require('pify');
const getPort = require('get-port');
exports.host = 'localhost';
const host = exports.host;
exports.createServer = function () {
return getPort().then(port => {
const s = http.createServer((req, resp) => s.emit(req.url, req, resp));
s.host = host;
s.port = port;
s.url = `http://${host}:${port}`;
s.protocol = 'http';
s.listen = pify(s.listen, Promise);
s.close = pify(s.close, Promise);
return s;
});
};
exports.createSSLServer = function (opts) {
return getPort().then(port => {
const s = https.createServer(opts, (req, resp) => s.emit(req.url, req, resp));
s.host = host;
s.port = port;
s.url = `https://${host}:${port}`;
s.protocol = 'https';
s.listen = pify(s.listen, Promise);
s.close = pify(s.close, Promise);
return s;
});
};