-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemon.js
34 lines (27 loc) · 815 Bytes
/
daemon.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
#!/usr/bin/env node
const { createDnsServer } = require('./dns');
const { createHttpProxyServer } = require('./http');
const { configDir } = require('./config');
async function main() {
const rootDomain = process.env.PROXY_ROOT_DOMAIN || 'localhost';
const httpServer = createHttpProxyServer(configDir, '.' + rootDomain);
httpServer.listen(80);
httpServer.on('listening', () => {
console.log('HTTP server listening');
});
const dnsServer = createDnsServer(configDir);
dnsServer.serve(53);
dnsServer.on('listening', () => {
console.log('DNS server listening');
});
process.on('SIGINT', () => {
console.log('Shutting down...');
httpServer.close();
dnsServer.close();
process.exit(0);
});
}
main().then(null, (err) => {
console.error(err);
process.exit(1);
});