@caboodle-tech/node-simple-server 1.2.5 → 1.3.0
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/changelogs/v1.md +4 -0
- package/package.json +1 -1
- package/server.js +19 -5
package/changelogs/v1.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caboodle-tech/node-simple-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Node Simple Server (NSS): A small but effective node based server for development sites and self controlled live reloading.",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"scripts": {
|
package/server.js
CHANGED
|
@@ -30,10 +30,11 @@ function NodeSimpleServer(options) {
|
|
|
30
30
|
root: Path.normalize(`${process.cwd()}/`),
|
|
31
31
|
running: false
|
|
32
32
|
};
|
|
33
|
+
const RELOAD = ['.html', '.htm'];
|
|
33
34
|
const SEP = Path.sep;
|
|
34
35
|
let SERVER = null;
|
|
35
36
|
let SOCKET = null;
|
|
36
|
-
const VERSION = '
|
|
37
|
+
const VERSION = '1.3.0'; // Update on releases.
|
|
37
38
|
const WATCHING = [];
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -503,12 +504,25 @@ function NodeSimpleServer(options) {
|
|
|
503
504
|
|
|
504
505
|
// Output the file to the browser.
|
|
505
506
|
response.writeHead(HTTPStatus.ok, getHeaders(contentType, safeURL));
|
|
506
|
-
response.write(file, 'binary');
|
|
507
507
|
|
|
508
|
-
//
|
|
509
|
-
|
|
510
|
-
|
|
508
|
+
// If needed inject NSS's WebSocket at the end of the page.
|
|
509
|
+
if (RELOAD.includes(Path.extname(safeURL))) {
|
|
510
|
+
let html = file.toString();
|
|
511
|
+
const last = html.lastIndexOf('</body>');
|
|
512
|
+
if (last && last > 0) {
|
|
513
|
+
const start = html.substr(0, last);
|
|
514
|
+
const end = html.substr(last);
|
|
515
|
+
html = start + inject + end;
|
|
516
|
+
response.write(html, 'utf8');
|
|
517
|
+
} else {
|
|
518
|
+
response.write(file, 'binary');
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
response.write(file, 'binary');
|
|
522
|
+
}
|
|
511
523
|
|
|
524
|
+
// Close initial connection.
|
|
525
|
+
response.end();
|
|
512
526
|
});
|
|
513
527
|
|
|
514
528
|
});
|