srv-it 0.4.0 → 0.4.1
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/license.md +20 -0
- package/package.json +1 -1
- package/src/cli.js +2 -1
- package/src/server.js +21 -9
package/license.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elouan Grimm.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
package/src/server.js
CHANGED
|
@@ -11,8 +11,19 @@ const os = require('node:os');
|
|
|
11
11
|
const chalk = require('chalk');
|
|
12
12
|
const { WebSocketServer } = require('ws');
|
|
13
13
|
|
|
14
|
+
const srvLogger = {
|
|
15
|
+
http: (...message) => console.info(chalk.bgBlue.bold(' HTTP '), ...message),
|
|
16
|
+
info: (...message) => console.info(chalk.bgMagenta.bold(' INFO '), ...message),
|
|
17
|
+
warn: (...message) => console.error(chalk.bgYellow.bold(' WARN '), ...message),
|
|
18
|
+
error: (...message) => console.error(chalk.bgRed.bold(' ERROR '), ...message),
|
|
19
|
+
log: console.log,
|
|
20
|
+
};
|
|
21
|
+
|
|
14
22
|
const BASE_WATCH_IGNORES = ['**/.git/**', '**/node_modules/**'];
|
|
15
23
|
|
|
24
|
+
const DIRECTORY_FAVICON_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#0c0a09" d="M3 5.5A2.5 2.5 0 0 1 5.5 3H10l2 2h6.5A2.5 2.5 0 0 1 21 7.5v9A2.5 2.5 0 0 1 18.5 19h-13A2.5 2.5 0 0 1 3 16.5z"/><path fill="#3b82f6" d="M3 8h18v8.5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 16.5z"/></svg>';
|
|
25
|
+
const DIRECTORY_FAVICON_DATA_URL = `data:image/svg+xml,${encodeURIComponent(DIRECTORY_FAVICON_SVG)}`;
|
|
26
|
+
|
|
16
27
|
function toGlobPath(value) {
|
|
17
28
|
return value.replace(/\\/g, '/');
|
|
18
29
|
}
|
|
@@ -106,6 +117,7 @@ function renderDirListing({ pathnameValue, entries, style, customCss }) {
|
|
|
106
117
|
<meta charset="utf-8" />
|
|
107
118
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
108
119
|
<title>Index of ${pathnameValue}</title>
|
|
120
|
+
<link rel="icon" href="${DIRECTORY_FAVICON_DATA_URL}" />
|
|
109
121
|
<style>
|
|
110
122
|
:root {
|
|
111
123
|
--stone-050: #fafaf9;
|
|
@@ -385,7 +397,7 @@ async function createSrvServer(options) {
|
|
|
385
397
|
res.statusCode = 500;
|
|
386
398
|
res.end('Internal server error');
|
|
387
399
|
if (options.logLevel >= 1) {
|
|
388
|
-
|
|
400
|
+
srvLogger.error('[srv] request error:', error.message);
|
|
389
401
|
}
|
|
390
402
|
} finally {
|
|
391
403
|
if (!options.noRequestLogging) {
|
|
@@ -396,7 +408,7 @@ async function createSrvServer(options) {
|
|
|
396
408
|
const formattedTime = `${now.toLocaleDateString()} ${now.toLocaleTimeString()}`;
|
|
397
409
|
const methodColor = method === 'GET' ? 'cyan' : 'magenta';
|
|
398
410
|
|
|
399
|
-
|
|
411
|
+
srvLogger.http(
|
|
400
412
|
chalk.dim(formattedTime),
|
|
401
413
|
chalk.yellow(sourceIp),
|
|
402
414
|
chalk[methodColor](`${method} ${pathnameValue}`),
|
|
@@ -420,7 +432,7 @@ async function createSrvServer(options) {
|
|
|
420
432
|
res.statusCode = 500;
|
|
421
433
|
res.end('Internal server error');
|
|
422
434
|
if (options.logLevel >= 1) {
|
|
423
|
-
|
|
435
|
+
srvLogger.error('[srv] handler error:', error.message);
|
|
424
436
|
}
|
|
425
437
|
});
|
|
426
438
|
});
|
|
@@ -430,7 +442,7 @@ async function createSrvServer(options) {
|
|
|
430
442
|
res.statusCode = 500;
|
|
431
443
|
res.end('Internal server error');
|
|
432
444
|
if (options.logLevel >= 1) {
|
|
433
|
-
|
|
445
|
+
srvLogger.error('[srv] handler error:', error.message);
|
|
434
446
|
}
|
|
435
447
|
});
|
|
436
448
|
});
|
|
@@ -474,7 +486,7 @@ async function createSrvServer(options) {
|
|
|
474
486
|
}
|
|
475
487
|
}
|
|
476
488
|
if (options.logLevel >= 2) {
|
|
477
|
-
|
|
489
|
+
srvLogger.info(`[srv] ${isCss ? 'css refresh' : 'reload'}: ${changePath}`);
|
|
478
490
|
}
|
|
479
491
|
};
|
|
480
492
|
|
|
@@ -487,13 +499,13 @@ async function createSrvServer(options) {
|
|
|
487
499
|
if (error && error.code === 'ENOSPC') {
|
|
488
500
|
liveReloadEnabled = false;
|
|
489
501
|
await closeWatcher();
|
|
490
|
-
|
|
491
|
-
|
|
502
|
+
srvLogger.error('[srv] live reload disabled: file watcher limit reached (ENOSPC).');
|
|
503
|
+
srvLogger.warn('[srv] use --ignore to exclude noisy paths, or raise inotify limits on Linux.');
|
|
492
504
|
return;
|
|
493
505
|
}
|
|
494
506
|
|
|
495
507
|
if (options.logLevel >= 1) {
|
|
496
|
-
|
|
508
|
+
srvLogger.error(`[srv] watcher error: ${error.message}`);
|
|
497
509
|
}
|
|
498
510
|
});
|
|
499
511
|
|
|
@@ -504,7 +516,7 @@ async function createSrvServer(options) {
|
|
|
504
516
|
};
|
|
505
517
|
|
|
506
518
|
process.on('SIGINT', async () => {
|
|
507
|
-
|
|
519
|
+
srvLogger.info('\n[srv] shutting down...');
|
|
508
520
|
await closeAll();
|
|
509
521
|
process.exit(0);
|
|
510
522
|
});
|