-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
executable file
·59 lines (46 loc) · 1.88 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
#!/usr/bin/env node
const ws = require('./chunkedGrowingWebserver.js');
const program = require('commander');
const path = require('path');
const fs = require('fs');
"use strict";
//Defaults
const base_dir_default = __dirname;
const port_default = 8080;
const host_default = '0.0.0.0';
const headers_by_ext_default = path.join(base_dir_default, 'config', 'headers.json');
const cors_default = path.join(base_dir_default, 'config', 'cors.json');
const public_fallback_dir_default = path.join(base_dir_default, 'config', 'public');
//Data
let base_dir = base_dir_default;
let port = port_default;
let host = host_default;
let headers_by_ext = headers_by_ext_default;
let cors = cors_default;
let public_fallback_dir = public_fallback_dir_default;
program
.version('1.1.0')
.description('Webserver that forces chunked transfer for growing files')
.option('-d, --directory [value]>', 'Base directory of your site [.]')
.option('-p, --port [n]', 'Listen port [8080]', parseInt)
.option('-a, --address [value]', 'Bind address [0.0.0.0]')
.option('-H, --headers [value]', 'Headers definition json file [./config/headers.json]')
.option('-c, --cors [value]', 'CORS definition file [./config/cors.json]')
.option('-f, --fallback [value]', 'Fallback directory [./config/public]')
.parse(process.argv);
if (program.directory)
base_dir = program.directory;
if (program.port)
port = program.port;
if (program.address)
host = program.address;
if (program.headers)
headers_by_ext = program.headers;
if (program.cors)
cors = program.cors;
if (program.fallback)
public_fallback_dir = program.fallback;
const headers_by_ext_obj = JSON.parse(fs.readFileSync(headers_by_ext));
const cors_obj = JSON.parse(fs.readFileSync(cors));
const webServer = new ws.chunkedGrowingWebserver(base_dir, port, host, headers_by_ext_obj, cors_obj, public_fallback_dir);
webServer.start();