-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
79 lines (66 loc) · 1.85 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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
const fs = require('fs');
const minimist = require('minimist');
const tessella = require('./src/server');
const packagejson = require('./package.json');
const config = minimist(process.argv.slice(2), {
string: ['port', 'socket', 'cacheSize', 'sourceCacheSize'],
boolean: ['cors'],
alias: {
h: 'help',
v: 'version'
},
default: {
cors: true,
port: 4000,
cacheSize: '10',
sourceCacheSize: 6
}
});
if (config.version) {
process.stdout.write(`${packagejson.version}\n`);
process.exit(0);
}
const help = () => {
const usage = `
Usage: tessella [options] [uri]
where [uri] is tilelive URI to serve and [options] is any of:
--port - port to run on (default: ${config.port})
--socket - use Unix socket instead of port
--cacheSize - cache size in MB (default: ${config.cacheSize})
--sourceCacheSize - source cache size in # of sources (default: ${
config.sourceCacheSize
})
--version - returns running version then exits
tessella@${packagejson.version}
node@${process.versions.node}
`;
process.stdout.write(`${usage}\n`);
process.exit(0);
};
if (config.help) {
help();
}
if (!config._[0]) {
process.stdout.write('URI not specified.\n\n');
help();
}
config.uri = config._[0];
const app = tessella(config);
const handler = config.socket || config.port;
const server = app.listen(handler, () => {
if (config.socket) {
fs.chmodSync(config.socket, '1766');
process.stdout.write(`🚀 ON AIR @ ${config.socket}`);
} else {
const endpoint = `${server.address().address}:${server.address().port}`;
process.stdout.write(`🚀 ON AIR @ ${endpoint}`);
}
});
const shutdown = () => {
process.stdout.write('Caught SIGINT, terminating\n');
server.close();
process.exit();
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);