-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (57 loc) · 1.82 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
const fs = require('fs');
const path = require('path');
const portType = require('port-type');
const { Server } = require('hapi');
const inert = require('inert');
/* eslint-disable global-require */
const routes = [
require('./lib/route/legacy'),
require('./lib/route/latest-build'),
require('./lib/route/build')
];
/* eslint-enable global-require */
class Nest extends Server {
constructor(option) {
const privileged = portType.haveRights(80);
const config = Object.assign(
{
insecurePort : privileged ? 80 : 3001,
port : privileged ? 443 : 3000,
tls : {
// Async configuration for constructors is a pain.
/* eslint-disable no-sync */
key : fs.readFileSync(path.join(__dirname, 'lib/key/localhost.key')),
cert : fs.readFileSync(path.join(__dirname, 'lib/cert/localhost-chain.cert'))
/* eslint-enable no-sync */
}
},
option
);
super();
super.connection({
port : config.port,
tls : config.tls
});
super.connection({
port : config.insecurePort
});
}
start() {
return super.register(inert).then(() => {
super.route(routes);
// Sadly, we cannot just return the start() promise because of:
// https://github.com/hapijs/hapi/issues/3217
return new Promise((resolve, reject) => {
super.start((err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
});
}
}
module.exports = Nest;