-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·42 lines (35 loc) · 1.11 KB
/
cli.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
#!/usr/bin/env node
const process = require('process');
const http = require('http');
const { createHandler } = require('./index.js');
const args = process.argv
.slice(2)
.map(arg => arg.split('='))
.reduce((args, [value, key]) => {
args[value] = key;
return args;
}, {});
const port = args['--port'] ? args['--port'] : 3838;
const dir = args['--dir'] ? args['--dir'] : './';
const rootPath = args['--root-path'] ? args['--root-path'] : '';
const securityMode = args['--security-mode'] ? args['--security-mode'] : '';
const ownerEmail = args['--email'] ? args['--email'] : '';
// Listen on all interfaces by default (0.0.0.0), but if securityMode is
// 'local' only bind to localhost unless overridden.
let host;
if (args['--host']) {
host = args['--host'];
}
else {
host = securityMode === 'local' ? '127.0.0.1' : '0.0.0.0';
}
(async () => {
const remfsHandler = await createHandler({ rootPath, dir, securityMode, ownerEmail });
const httpServer = http.createServer(remfsHandler);
if (securityMode === 'local') {
httpServer.listen(port, host);
}
else {
httpServer.listen(port);
}
})();