safely-serve 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint.config.mjs +67 -31
- package/fs-worker.js +1 -1
- package/libsafely-serve +181 -131
- package/package.json +7 -3
- package/safely-serve +412 -254
- package/safely-serve.js +1 -1
package/safely-serve
CHANGED
|
@@ -2,112 +2,267 @@
|
|
|
2
2
|
|
|
3
3
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
/** ----------------------------------------------------------------------
|
|
6
|
+
* safely-serve
|
|
7
|
+
* ----------------------------------------------------------------------
|
|
8
|
+
* Copyright ©
|
|
9
|
+
* Pellegrino Prevete
|
|
10
|
+
* 2024, 2025, 2026
|
|
11
|
+
*
|
|
12
|
+
* All rights reserved
|
|
13
|
+
* ----------------------------------------------------------------------
|
|
14
|
+
*
|
|
15
|
+
* This program is free software: you can redistribute it and/or modify
|
|
16
|
+
* it under the terms of the GNU General Public License as published by
|
|
17
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
18
|
+
* (at your option) any later version.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/* eslint
|
|
30
|
+
no-undef:
|
|
31
|
+
"error" */
|
|
32
|
+
/* eslint
|
|
33
|
+
no-unused-vars: [
|
|
34
|
+
"error",
|
|
35
|
+
{ "vars":
|
|
36
|
+
"local",
|
|
37
|
+
"varsIgnorePattern":
|
|
38
|
+
"_input_args_check" } ] */
|
|
23
39
|
|
|
24
40
|
const
|
|
25
41
|
_os =
|
|
26
42
|
require(
|
|
27
43
|
"os");
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
const
|
|
45
|
+
_homedir =
|
|
46
|
+
_os.homedir;
|
|
30
47
|
const
|
|
31
48
|
_libcrash =
|
|
32
49
|
require(
|
|
33
50
|
'crash-js');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
/* global
|
|
52
|
+
_cmdline_check */
|
|
53
|
+
const
|
|
54
|
+
_cmdline_check =
|
|
55
|
+
_libcrash._cmdline_check;
|
|
56
|
+
/* global
|
|
57
|
+
_msg_info */
|
|
58
|
+
const
|
|
59
|
+
_msg_info =
|
|
60
|
+
_libcrash._msg_info;
|
|
61
|
+
/* global
|
|
62
|
+
_msg_error */
|
|
63
|
+
const
|
|
64
|
+
_msg_error =
|
|
65
|
+
_libcrash._msg_error;
|
|
66
|
+
/* global
|
|
67
|
+
_path_join */
|
|
68
|
+
const
|
|
69
|
+
_path_join =
|
|
70
|
+
_libcrash._path_join;
|
|
71
|
+
/* global
|
|
72
|
+
_process_exit */
|
|
73
|
+
const
|
|
74
|
+
_process_exit =
|
|
75
|
+
_libcrash._process_exit;
|
|
76
|
+
/* global
|
|
77
|
+
_pwd */
|
|
78
|
+
const
|
|
79
|
+
_pwd =
|
|
80
|
+
_libcrash._pwd;
|
|
81
|
+
/* global
|
|
82
|
+
_argv_url_get */
|
|
83
|
+
const
|
|
84
|
+
_argv_url_get =
|
|
85
|
+
_libcrash._argv_url_get;
|
|
86
|
+
/* global
|
|
87
|
+
_yargv_get */
|
|
88
|
+
const
|
|
89
|
+
_yargv_get =
|
|
90
|
+
_libcrash._yargv_get;
|
|
42
91
|
const
|
|
43
92
|
_libsafely_serve_module =
|
|
44
93
|
require(
|
|
45
94
|
"./libsafely-serve");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
95
|
+
/* global
|
|
96
|
+
_path_encode */
|
|
97
|
+
const
|
|
98
|
+
_path_encode =
|
|
99
|
+
_libsafely_serve_module._path_encode;
|
|
100
|
+
/* global
|
|
101
|
+
_safely_serve */
|
|
102
|
+
const
|
|
103
|
+
_safely_serve =
|
|
104
|
+
_libsafely_serve_module._safely_serve;
|
|
50
105
|
|
|
51
106
|
function
|
|
52
107
|
_global_variables() {
|
|
108
|
+
/* global
|
|
109
|
+
app_name:
|
|
110
|
+
writable */
|
|
53
111
|
app_name =
|
|
54
112
|
"safely-serve";
|
|
113
|
+
/* global
|
|
114
|
+
app_opts:
|
|
115
|
+
writable */
|
|
116
|
+
app_opts =
|
|
117
|
+
[];
|
|
118
|
+
/* global
|
|
119
|
+
runtime_environment:
|
|
120
|
+
writable */
|
|
55
121
|
target_directory =
|
|
56
122
|
"";
|
|
123
|
+
/* global
|
|
124
|
+
target_directory:
|
|
125
|
+
writable */
|
|
126
|
+
target_directory =
|
|
127
|
+
"";
|
|
128
|
+
/* global
|
|
129
|
+
listen_uris:
|
|
130
|
+
writable */
|
|
57
131
|
listen_uris =
|
|
58
132
|
[];
|
|
133
|
+
/* global
|
|
134
|
+
target_port:
|
|
135
|
+
writable */
|
|
59
136
|
target_port =
|
|
60
137
|
"";
|
|
138
|
+
/* global
|
|
139
|
+
index_redirect:
|
|
140
|
+
writable */
|
|
61
141
|
index_redirect =
|
|
62
142
|
"";
|
|
143
|
+
/* global
|
|
144
|
+
debug_enabled:
|
|
145
|
+
writable */
|
|
63
146
|
debug_enabled =
|
|
64
147
|
"";
|
|
148
|
+
/* global
|
|
149
|
+
config_file:
|
|
150
|
+
writable */
|
|
65
151
|
config_file =
|
|
66
152
|
"";
|
|
153
|
+
/* global
|
|
154
|
+
logging_disabled:
|
|
155
|
+
writable */
|
|
67
156
|
logging_disabled =
|
|
68
157
|
"";
|
|
158
|
+
/* global
|
|
159
|
+
cors_enabled:
|
|
160
|
+
writable */
|
|
69
161
|
cors_enabled =
|
|
70
162
|
"";
|
|
163
|
+
/* global
|
|
164
|
+
clipboard_disabled:
|
|
165
|
+
writable */
|
|
71
166
|
clipboard_disabled =
|
|
72
167
|
"";
|
|
168
|
+
/* global
|
|
169
|
+
compression_disabled:
|
|
170
|
+
writable */
|
|
73
171
|
compression_disabled =
|
|
74
172
|
"";
|
|
173
|
+
/* global
|
|
174
|
+
etag_disabled:
|
|
175
|
+
writable*/
|
|
75
176
|
etag_disabled =
|
|
76
177
|
"";
|
|
178
|
+
/* global
|
|
179
|
+
symlinks_enabled:
|
|
180
|
+
writable */
|
|
77
181
|
symlinks_enabled =
|
|
78
182
|
"";
|
|
183
|
+
/* global
|
|
184
|
+
ssl_cert:
|
|
185
|
+
writable */
|
|
79
186
|
ssl_cert =
|
|
80
187
|
"";
|
|
188
|
+
/* global
|
|
189
|
+
ssl_key:
|
|
190
|
+
writable */
|
|
81
191
|
ssl_key =
|
|
82
192
|
"";
|
|
193
|
+
/* global
|
|
194
|
+
ssl_pass:
|
|
195
|
+
writable */
|
|
83
196
|
ssl_pass =
|
|
84
197
|
"";
|
|
198
|
+
/* global
|
|
199
|
+
cert_gen:
|
|
200
|
+
writable */
|
|
85
201
|
cert_gen =
|
|
86
202
|
"";
|
|
203
|
+
/* global
|
|
204
|
+
port_switching_disabled:
|
|
205
|
+
writable */
|
|
87
206
|
port_switching_disabled =
|
|
88
207
|
"";
|
|
208
|
+
/* global
|
|
209
|
+
keys_length:
|
|
210
|
+
writable */
|
|
89
211
|
keys_length =
|
|
90
212
|
"";
|
|
213
|
+
/* global
|
|
214
|
+
serial_number:
|
|
215
|
+
writable */
|
|
91
216
|
serial_number =
|
|
92
217
|
"";
|
|
218
|
+
/* global
|
|
219
|
+
validity_min:
|
|
220
|
+
writable*/
|
|
93
221
|
validity_min =
|
|
94
222
|
"";
|
|
223
|
+
/* global
|
|
224
|
+
validity_max:
|
|
225
|
+
writable */
|
|
95
226
|
validity_max =
|
|
96
227
|
"";
|
|
228
|
+
/* global
|
|
229
|
+
domain_name:
|
|
230
|
+
writable */
|
|
97
231
|
domain_name =
|
|
98
232
|
"";
|
|
233
|
+
/* global
|
|
234
|
+
country_name:
|
|
235
|
+
writable */
|
|
99
236
|
country_name =
|
|
100
237
|
"";
|
|
238
|
+
/* global
|
|
239
|
+
state_name:
|
|
240
|
+
writable */
|
|
101
241
|
state_name =
|
|
102
242
|
"";
|
|
243
|
+
/* global
|
|
244
|
+
locality_name:
|
|
245
|
+
writable */
|
|
103
246
|
locality_name =
|
|
104
247
|
"";
|
|
248
|
+
/* global
|
|
249
|
+
organization_name:
|
|
250
|
+
writable */
|
|
105
251
|
organization_name =
|
|
106
252
|
"";
|
|
253
|
+
/* global
|
|
254
|
+
organization_unit:
|
|
255
|
+
writable */
|
|
107
256
|
organization_unit =
|
|
108
257
|
"";
|
|
258
|
+
/* global
|
|
259
|
+
cache_dir:
|
|
260
|
+
writable */
|
|
109
261
|
cache_dir =
|
|
110
262
|
"";
|
|
263
|
+
/* global
|
|
264
|
+
quiet:
|
|
265
|
+
writable */
|
|
111
266
|
quiet =
|
|
112
267
|
"";
|
|
113
268
|
}
|
|
@@ -121,25 +276,24 @@ function
|
|
|
121
276
|
function
|
|
122
277
|
_work_dir_get(
|
|
123
278
|
_target_directory) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
279
|
+
const
|
|
280
|
+
_target_directory_encoded =
|
|
281
|
+
_path_encode(
|
|
282
|
+
_target_directory);
|
|
283
|
+
const
|
|
284
|
+
_work_dir =
|
|
285
|
+
_path_join( [
|
|
286
|
+
cache_dir,
|
|
287
|
+
_target_directory_encoded ]);
|
|
133
288
|
return _work_dir;
|
|
134
289
|
}
|
|
135
290
|
|
|
136
291
|
function
|
|
137
292
|
_ssl_config_auto_detect() {
|
|
138
|
-
|
|
139
|
-
_work_dir
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
target_directory);
|
|
293
|
+
const
|
|
294
|
+
_work_dir =
|
|
295
|
+
_work_dir_get(
|
|
296
|
+
target_directory);
|
|
143
297
|
if ( ssl_cert == "" ) {
|
|
144
298
|
ssl_cert =
|
|
145
299
|
`${_work_dir}/cert.pem`;
|
|
@@ -168,7 +322,7 @@ function
|
|
|
168
322
|
_cache_dir_auto_detect();
|
|
169
323
|
if ( target_directory == "" ) {
|
|
170
324
|
target_directory =
|
|
171
|
-
|
|
325
|
+
_pwd();
|
|
172
326
|
}
|
|
173
327
|
if ( target_port == "" ) {
|
|
174
328
|
target_port =
|
|
@@ -255,41 +409,41 @@ function
|
|
|
255
409
|
function
|
|
256
410
|
_config_show() {
|
|
257
411
|
let
|
|
258
|
-
_line
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
412
|
+
_line;
|
|
413
|
+
const
|
|
414
|
+
_text = [
|
|
415
|
+
`${app_name} configuration:`,
|
|
416
|
+
` Runtime environment: ${runtime_environment}`,
|
|
417
|
+
` Target directory: ${target_directory}`,
|
|
418
|
+
` Serve options:`,
|
|
419
|
+
` Listen URIs: ${listen_uris}`,
|
|
420
|
+
` Target port: ${target_port}`,
|
|
421
|
+
` Index redirect: ${index_redirect}`,
|
|
422
|
+
` Configuration file: ${config_file}`,
|
|
423
|
+
` Quiet stdout log: ${logging_disabled}`,
|
|
424
|
+
` Cors: ${cors_enabled}`,
|
|
425
|
+
` No clipboard: ${clipboard_disabled}`,
|
|
426
|
+
` No compression: ${compression_disabled}`,
|
|
427
|
+
` Disable ETag: ${etag_disabled}`,
|
|
428
|
+
` Symlinks: ${symlinks_enabled}`,
|
|
429
|
+
` No port switching: ${port_switching_disabled}`,
|
|
430
|
+
` SSL options:`,
|
|
431
|
+
` Generate certificate: ${cert_gen}`,
|
|
432
|
+
` SSL Certificate: ${ssl_cert}`,
|
|
433
|
+
` SSL private key: ${ssl_key}`,
|
|
434
|
+
` Key password: ${ssl_pass}`,
|
|
435
|
+
` Certificate options:`,
|
|
436
|
+
` Key length: ${keys_length}`,
|
|
437
|
+
` Serial number: ${serial_number}`,
|
|
438
|
+
` Valid after: ${validity_min}`,
|
|
439
|
+
` Expires on: ${validity_max}`,
|
|
440
|
+
` Domain name: ${domain_name}`,
|
|
441
|
+
` Country: ${country_name}`,
|
|
442
|
+
` State: ${state_name}`,
|
|
443
|
+
` Locality: ${locality_name}`,
|
|
444
|
+
` Organization: ${organization_name}`,
|
|
445
|
+
` Organization unit: ${organization_unit}`,
|
|
446
|
+
];
|
|
293
447
|
for ( _line of _text ) {
|
|
294
448
|
_msg_info(
|
|
295
449
|
_line);
|
|
@@ -300,120 +454,119 @@ function
|
|
|
300
454
|
_usage(
|
|
301
455
|
_exit_code) {
|
|
302
456
|
let
|
|
303
|
-
_line
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
457
|
+
_line;
|
|
458
|
+
const
|
|
459
|
+
_text = [
|
|
460
|
+
"",
|
|
461
|
+
"Serve extension which generates a self-signed SSL certificate at runtime.",
|
|
462
|
+
"",
|
|
463
|
+
"Usage:",
|
|
464
|
+
"",
|
|
465
|
+
" safely-serve",
|
|
466
|
+
" [options]",
|
|
467
|
+
" <target-directory>",
|
|
468
|
+
"",
|
|
469
|
+
" serve options:",
|
|
470
|
+
" -l, --listen=URI Specify a URI endpoint on",
|
|
471
|
+
" which to listen (see below);",
|
|
472
|
+
" more than one may be specified to",
|
|
473
|
+
" listen in multiple places.",
|
|
474
|
+
` Default: '${listen_uris}'`,
|
|
475
|
+
" -p, --port=PORT Specify custom port",
|
|
476
|
+
` Default: '${target_port}'`,
|
|
477
|
+
" -s, --single Rewrite all not-found requests",
|
|
478
|
+
" to 'index.html'.",
|
|
479
|
+
` Default: '${index_redirect}'`,
|
|
480
|
+
" -d, --debug Show debugging information.",
|
|
481
|
+
` Default: '${debug_enabled}'`,
|
|
482
|
+
" -c, --config=PATH Specify custom path to 'serve.json'.",
|
|
483
|
+
` Default: '${config_file}'`,
|
|
484
|
+
" -L, --no-request-logging Do not log any request information",
|
|
485
|
+
" to the console.",
|
|
486
|
+
` Default: '${logging_disabled}'`,
|
|
487
|
+
" -C, --cors Enable CORS, sets",
|
|
488
|
+
" 'Access-Control-Allow-Origin'",
|
|
489
|
+
" to '*'.",
|
|
490
|
+
` Default: '${cors_enabled}'`,
|
|
491
|
+
" -n, --no-clipboard Do not copy the local address",
|
|
492
|
+
" to the clipboard.",
|
|
493
|
+
` Default: '${clipboard_disabled}'`,
|
|
494
|
+
" -u, --no-compression Do not compress files.",
|
|
495
|
+
` Default: '${compression_disabled}'`,
|
|
496
|
+
" -e, --no-etag Send 'Last-Modified' header",
|
|
497
|
+
" instead of `ETag`.",
|
|
498
|
+
` Default: '${etag_disabled}'`,
|
|
499
|
+
" -S, --symlinks Resolve symlinks instead of",
|
|
500
|
+
" showing 404 errors.",
|
|
501
|
+
` Default: '${symlinks_enabled}'`,
|
|
502
|
+
" --no-port-switching Do not open a port other than",
|
|
503
|
+
" the one specified when it's taken.",
|
|
504
|
+
` Default: '${port_switching_disabled}'`,
|
|
505
|
+
" ssl options:",
|
|
506
|
+
" -g, --gen-cert If enabled, generate self-signed certificate",
|
|
507
|
+
" at the specified path.",
|
|
508
|
+
` Default: '${cert_gen}'`,
|
|
509
|
+
" -I, --ssl-cert=PATH Optional path to an SSL/TLS",
|
|
510
|
+
" certificate to serve with HTTPS.",
|
|
511
|
+
" Supported formats: PEM (default)",
|
|
512
|
+
" and PKCS12 (PFX)",
|
|
513
|
+
` Default: '${ssl_cert}'`,
|
|
514
|
+
" -i, --ssl-key=PATH Optional path to the SSL/TLS",
|
|
515
|
+
" certificate's private key.",
|
|
516
|
+
" Applicable only for PEM certificates.",
|
|
517
|
+
` Default: '${ssl_key}'`,
|
|
518
|
+
" -k --ssl-pass=PATH Optional path to the SSL/TLS",
|
|
519
|
+
" certificate's passphrase.",
|
|
520
|
+
` Default: '${ssl_pass}'`,
|
|
521
|
+
"",
|
|
522
|
+
" certificate options:",
|
|
523
|
+
" -N, --keys-length=N Generated keys pair length.",
|
|
524
|
+
` Default: '${keys_length}'`,
|
|
525
|
+
" -B, --validity-min=DATE Set activation date.",
|
|
526
|
+
` Default: '${validity_min}'`,
|
|
527
|
+
" -E, --validity-max=DATE Set expiration date.",
|
|
528
|
+
` Default: '${validity_max}'`,
|
|
529
|
+
" -D, --domain-name=DOMAIN Set domain name.",
|
|
530
|
+
` Default: '${domain_name}'`,
|
|
531
|
+
" -C, --country-name=COUNTRY Set country name.",
|
|
532
|
+
` Default: '${country_name}'`,
|
|
533
|
+
" -S, --state-name=STATE Set state name.",
|
|
534
|
+
` Default: '${state_name}'`,
|
|
535
|
+
" --locality-name=LOCALITY Set locality name.",
|
|
536
|
+
` Default: '${locality_name}'`,
|
|
537
|
+
" -O, --organization-name=ORG Set organization name.",
|
|
538
|
+
` Default: '${organization_name}'`,
|
|
539
|
+
" -U, --organization-unit=UNIT Set organization unit.",
|
|
540
|
+
` Default: '${organization_unit}'`,
|
|
541
|
+
" -X, --serial-number=SERIAL Set serial number.",
|
|
542
|
+
` Default: '${serial_number}'`,
|
|
543
|
+
"",
|
|
544
|
+
" application options:",
|
|
545
|
+
" -N, --keys-length=N Generated keys pair length.",
|
|
546
|
+
" -W, --cache-dir Work directory.",
|
|
547
|
+
` Default: '${cache_dir}'`,
|
|
548
|
+
" -v, --version Displays the current version of",
|
|
549
|
+
" Safely Serve.",
|
|
550
|
+
" -h, --help Shows this help message.",
|
|
551
|
+
"",
|
|
552
|
+
];
|
|
399
553
|
for ( _line of _text ) {
|
|
400
554
|
console.log(
|
|
401
555
|
_line);
|
|
402
556
|
}
|
|
403
|
-
|
|
557
|
+
_process_exit(
|
|
404
558
|
_exit_code);
|
|
405
559
|
}
|
|
406
560
|
|
|
407
561
|
function
|
|
408
562
|
_cmdline_parse_help(
|
|
409
563
|
_argv) {
|
|
410
|
-
|
|
411
|
-
_help_display
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
"h"];
|
|
564
|
+
const
|
|
565
|
+
_help_display =
|
|
566
|
+
_argv[
|
|
567
|
+
"help"] ||
|
|
568
|
+
_argv[
|
|
569
|
+
"h"];
|
|
417
570
|
if ( _help_display ) {
|
|
418
571
|
quiet =
|
|
419
572
|
"n";
|
|
@@ -442,8 +595,9 @@ function
|
|
|
442
595
|
_argv) {
|
|
443
596
|
if ( _argv[
|
|
444
597
|
"_"].length < 1 ) {
|
|
445
|
-
|
|
446
|
-
|
|
598
|
+
const
|
|
599
|
+
_msg =
|
|
600
|
+
"Target directory required.";
|
|
447
601
|
_msg_error(
|
|
448
602
|
_msg,
|
|
449
603
|
0);
|
|
@@ -463,9 +617,16 @@ function
|
|
|
463
617
|
0];
|
|
464
618
|
if ( typeof _target_directory === 'undefined' ) {
|
|
465
619
|
_target_directory =
|
|
466
|
-
|
|
467
|
-
return _target_directory;
|
|
468
|
-
|
|
620
|
+
_pwd();
|
|
621
|
+
return _target_directory;
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
const
|
|
625
|
+
_msg =
|
|
626
|
+
`Target directory value ` +
|
|
627
|
+
`'${_target_directory}'.`;
|
|
628
|
+
_msg_info(
|
|
629
|
+
_msg);
|
|
469
630
|
}
|
|
470
631
|
return _target_directory;
|
|
471
632
|
}
|
|
@@ -480,9 +641,10 @@ function
|
|
|
480
641
|
_value;
|
|
481
642
|
if ( _letter_opt in _argv &&
|
|
482
643
|
_word_opt in _argv ) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
644
|
+
const
|
|
645
|
+
_msg =
|
|
646
|
+
`You can only use ` +
|
|
647
|
+
`'${_letter_opt}' or '--${_word_opt}'`;
|
|
486
648
|
_msg_error(
|
|
487
649
|
_msg,
|
|
488
650
|
1);
|
|
@@ -510,12 +672,9 @@ function
|
|
|
510
672
|
|
|
511
673
|
function
|
|
512
674
|
_cmdline_parse() {
|
|
513
|
-
|
|
514
|
-
_argv
|
|
515
|
-
|
|
516
|
-
_target_directory;
|
|
517
|
-
_argv =
|
|
518
|
-
_yargv_get();
|
|
675
|
+
const
|
|
676
|
+
_argv =
|
|
677
|
+
_yargv_get();
|
|
519
678
|
quiet =
|
|
520
679
|
"y";
|
|
521
680
|
runtime_environment =
|
|
@@ -657,110 +816,109 @@ function
|
|
|
657
816
|
|
|
658
817
|
function
|
|
659
818
|
_url_parse() {
|
|
660
|
-
let
|
|
661
|
-
_argv;
|
|
662
819
|
runtime_environment =
|
|
663
820
|
"browser";
|
|
664
|
-
|
|
665
|
-
|
|
821
|
+
const
|
|
822
|
+
_argv =
|
|
823
|
+
_argv_url_get();
|
|
666
824
|
target_directory =
|
|
667
|
-
|
|
668
|
-
"target_directory"
|
|
825
|
+
_argv[
|
|
826
|
+
"target_directory"][
|
|
669
827
|
0];
|
|
670
828
|
listen_uris =
|
|
671
|
-
|
|
672
|
-
"listen"
|
|
829
|
+
_argv[
|
|
830
|
+
"listen"];
|
|
673
831
|
target_port =
|
|
674
|
-
|
|
675
|
-
"port"
|
|
832
|
+
_argv[
|
|
833
|
+
"port"][
|
|
676
834
|
0];
|
|
677
835
|
index_redirect =
|
|
678
|
-
|
|
679
|
-
"single"
|
|
836
|
+
_argv[
|
|
837
|
+
"single"][
|
|
680
838
|
0];
|
|
681
839
|
config_file =
|
|
682
|
-
|
|
683
|
-
"config_file"
|
|
840
|
+
_argv[
|
|
841
|
+
"config_file"][
|
|
684
842
|
0];
|
|
685
843
|
compression_disabled =
|
|
686
|
-
|
|
687
|
-
"no_compression"
|
|
844
|
+
_argv[
|
|
845
|
+
"no_compression"][
|
|
688
846
|
0];
|
|
689
847
|
etag_disabled =
|
|
690
|
-
|
|
691
|
-
"no_etag"
|
|
848
|
+
_argv[
|
|
849
|
+
"no_etag"][
|
|
692
850
|
0];
|
|
693
851
|
logging_disabled =
|
|
694
|
-
|
|
695
|
-
"no_request_logging"
|
|
852
|
+
_argv[
|
|
853
|
+
"no_request_logging"][
|
|
696
854
|
0];
|
|
697
855
|
cors_enabled =
|
|
698
|
-
|
|
699
|
-
"cors"
|
|
856
|
+
_argv[
|
|
857
|
+
"cors"][
|
|
700
858
|
0];
|
|
701
859
|
clipboard_disabled =
|
|
702
|
-
|
|
703
|
-
"no_clipboard"
|
|
860
|
+
_argv[
|
|
861
|
+
"no_clipboard"][
|
|
704
862
|
0];
|
|
705
863
|
ssl_cert =
|
|
706
|
-
|
|
707
|
-
"ssl_cert"
|
|
864
|
+
_argv[
|
|
865
|
+
"ssl_cert"][
|
|
708
866
|
0];
|
|
709
867
|
port_switching_disabled =
|
|
710
|
-
|
|
711
|
-
"no_compression"
|
|
868
|
+
_argv[
|
|
869
|
+
"no_compression"][
|
|
712
870
|
0];
|
|
713
871
|
symlinks_enabled =
|
|
714
|
-
|
|
715
|
-
"symlinks"
|
|
872
|
+
_argv[
|
|
873
|
+
"symlinks"][
|
|
716
874
|
0];
|
|
717
875
|
ssl_key =
|
|
718
|
-
|
|
719
|
-
"ssl_key"
|
|
876
|
+
_argv[
|
|
877
|
+
"ssl_key"][
|
|
720
878
|
0];
|
|
721
879
|
keys_length =
|
|
722
|
-
|
|
723
|
-
"keys_length"
|
|
880
|
+
_argv[
|
|
881
|
+
"keys_length"][
|
|
724
882
|
0];
|
|
725
883
|
validity_min =
|
|
726
|
-
|
|
727
|
-
"validity_min"
|
|
884
|
+
_argv[
|
|
885
|
+
"validity_min"][
|
|
728
886
|
0];
|
|
729
887
|
validity_max =
|
|
730
|
-
|
|
731
|
-
"validity_max"
|
|
888
|
+
_argv[
|
|
889
|
+
"validity_max"][
|
|
732
890
|
0];
|
|
733
891
|
country_name =
|
|
734
|
-
|
|
735
|
-
"country_name"
|
|
892
|
+
_argv[
|
|
893
|
+
"country_name"][
|
|
736
894
|
0];
|
|
737
895
|
state_name =
|
|
738
|
-
|
|
739
|
-
"state_name"
|
|
896
|
+
_argv[
|
|
897
|
+
"state_name"][
|
|
740
898
|
0];
|
|
741
899
|
locality_name =
|
|
742
|
-
|
|
743
|
-
"locality_name"
|
|
900
|
+
_argv[
|
|
901
|
+
"locality_name"][
|
|
744
902
|
0];
|
|
745
903
|
organization_name =
|
|
746
|
-
|
|
747
|
-
"organization_name"
|
|
904
|
+
_argv[
|
|
905
|
+
"organization_name"][
|
|
748
906
|
0];
|
|
749
907
|
organization_unit =
|
|
750
|
-
|
|
751
|
-
"organization_unit"
|
|
908
|
+
_argv[
|
|
909
|
+
"organization_unit"][
|
|
752
910
|
0];
|
|
753
911
|
serial_number =
|
|
754
|
-
|
|
755
|
-
"serial_number"
|
|
912
|
+
_argv[
|
|
913
|
+
"serial_number"][
|
|
756
914
|
0];
|
|
757
915
|
cache_dir =
|
|
758
|
-
|
|
759
|
-
"cache_dir"
|
|
916
|
+
_argv[
|
|
917
|
+
"cache_dir"][
|
|
760
918
|
0];
|
|
761
919
|
quiet =
|
|
762
|
-
|
|
763
|
-
"quiet"
|
|
920
|
+
_argv[
|
|
921
|
+
"quiet"];
|
|
764
922
|
if ( quiet.length === 0 ) {
|
|
765
923
|
quiet =
|
|
766
924
|
"n";
|