@caboodle-tech/node-simple-server 1.2.2 → 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/README.md +11 -11
- package/changelogs/v1.md +9 -0
- package/package.json +2 -2
- package/server.js +25 -11
package/README.md
CHANGED
|
@@ -4,20 +4,20 @@ Node Simple Server (NSS) is a small but effective node based server for developm
|
|
|
4
4
|
|
|
5
5
|
:heavy_check_mark: You want to add live reloading to the development process of a static site.
|
|
6
6
|
|
|
7
|
-
:heavy_check_mark: You want easy two-way communication from the back-end and front-end of your development site
|
|
7
|
+
:heavy_check_mark: You want easy two-way communication from the back-end and front-end of your development site; WebSockets managed for you.
|
|
8
8
|
|
|
9
9
|
:heavy_check_mark: You want more fine grained control over the whole live reloading process.
|
|
10
10
|
|
|
11
|
-
:heavy_check_mark: You want to easily test your development site on multiple devices
|
|
11
|
+
:heavy_check_mark: You want to easily test your development site on multiple devices; must be on the same LAN.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
15
|
### Manually:
|
|
16
16
|
|
|
17
|
-
NSS can be manually incorporated into your development process/ application. Extract the `nss` folder from the [latest release](https://github.com/caboodle-tech/
|
|
17
|
+
Noe Simple Server (NSS) can be manually incorporated into your development process/ application. Extract the `nss` folder from the [latest release](https://github.com/caboodle-tech/node-simple-server/releases/) and then `require` the server module into your code, similar to:
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
|
-
const
|
|
20
|
+
const NodeSimpleServer = require("./node-simple-server/server");
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
### Locally:
|
|
@@ -26,10 +26,10 @@ You can install and use NSS locally in a project with:
|
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
// As a normal dependency:
|
|
29
|
-
npm install @caboodle-tech/
|
|
29
|
+
npm install @caboodle-tech/node-simple-server
|
|
30
30
|
|
|
31
31
|
// or as a development dependency:
|
|
32
|
-
npm install @caboodle-tech/
|
|
32
|
+
npm install @caboodle-tech/node-simple-server --save-dev
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Depending on how you use and incorporate NSS into your project will determine what it's dependency type should be.
|
|
@@ -39,7 +39,7 @@ Depending on how you use and incorporate NSS into your project will determine wh
|
|
|
39
39
|
You can install and use NSS globally with:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
npm install --global @caboodle-tech/
|
|
42
|
+
npm install --global @caboodle-tech/node-simple-server
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## Usage
|
|
@@ -48,10 +48,10 @@ NSS is designed to be controlled and/or wrapped by another application. The bare
|
|
|
48
48
|
|
|
49
49
|
```javascript
|
|
50
50
|
// Require NSS. Here it is required from a manual install.
|
|
51
|
-
const
|
|
51
|
+
const NodeSimpleServer = require("./server");
|
|
52
52
|
|
|
53
53
|
// Get a new instance of NSS.
|
|
54
|
-
const Server = new
|
|
54
|
+
const Server = new NodeSimpleServer();
|
|
55
55
|
|
|
56
56
|
// Start the server.
|
|
57
57
|
Server.start();
|
|
@@ -83,7 +83,7 @@ NSS uses the current working directory as the live servers root and is pre-confi
|
|
|
83
83
|
const options = {...};
|
|
84
84
|
|
|
85
85
|
// Get a new instance of NSS and pass in the options.
|
|
86
|
-
const Server = new
|
|
86
|
+
const Server = new NodeSimpleServer(options);
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
### :bookmark: Server Options (Object)
|
|
@@ -244,4 +244,4 @@ The [current changelog is here](./changelogs/v1.md). All [other changelogs are h
|
|
|
244
244
|
|
|
245
245
|
## Contributions
|
|
246
246
|
|
|
247
|
-
NSS is an open source community supported project, if you would like to help please consider <a href="https://github.com/caboodle-tech/
|
|
247
|
+
NSS is an open source community supported project, if you would like to help please consider <a href="https://github.com/caboodle-tech/node-simple-server/issues" target="_blank">tackling an issue</a> or <a href="https://ko-fi.com/caboodletech" target="_blank">making a donation</a> to keep the project alive.
|
package/changelogs/v1.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
### NSS 1.3.0 (23 Nov 2021)
|
|
2
|
+
|
|
3
|
+
- Bug Fix: Inject script and styles are now correctly added to HTML files only.
|
|
4
|
+
|
|
5
|
+
### NSS 1.2.5 (26 Oct 2021)
|
|
6
|
+
|
|
7
|
+
- README corrections.
|
|
8
|
+
- moved the server live message.
|
|
9
|
+
|
|
1
10
|
### NSS 1.2.2 (15 Oct 2021)
|
|
2
11
|
|
|
3
12
|
- Renamed repository and NPM package to `Node Simple Server`.
|
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": {
|
|
@@ -39,4 +39,4 @@
|
|
|
39
39
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
40
40
|
"eslint-plugin-import": "^2.25.2"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
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
|
/**
|
|
@@ -42,14 +43,14 @@ function NodeSimpleServer(options) {
|
|
|
42
43
|
*
|
|
43
44
|
* @return {Array} An array of loop back ip addresses and LAN addresses to this server.
|
|
44
45
|
*/
|
|
45
|
-
const getAddresses = function () {
|
|
46
|
+
const getAddresses = function (port) {
|
|
46
47
|
const locals = getLocalAddresses();
|
|
47
48
|
const addresses = [
|
|
48
|
-
`http://localhost:${
|
|
49
|
-
`http://127.0.0.1:${
|
|
49
|
+
`http://localhost:${port}`,
|
|
50
|
+
`http://127.0.0.1:${port}`
|
|
50
51
|
];
|
|
51
52
|
Object.keys(locals).forEach((key) => {
|
|
52
|
-
addresses.push(`http://${locals[key]}:${
|
|
53
|
+
addresses.push(`http://${locals[key]}:${port}`);
|
|
53
54
|
});
|
|
54
55
|
return addresses;
|
|
55
56
|
};
|
|
@@ -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
|
});
|
|
@@ -663,7 +677,7 @@ function NodeSimpleServer(options) {
|
|
|
663
677
|
|
|
664
678
|
// Log the ip addresses being watched.
|
|
665
679
|
console.log('Node Simple Server live @:');
|
|
666
|
-
const addresses = getAddresses();
|
|
680
|
+
const addresses = getAddresses(port);
|
|
667
681
|
addresses.forEach((address) => {
|
|
668
682
|
console.log(` ${address}`);
|
|
669
683
|
});
|
|
@@ -701,8 +715,8 @@ function NodeSimpleServer(options) {
|
|
|
701
715
|
SERVER = null;
|
|
702
716
|
SOCKET = null;
|
|
703
717
|
OP.running = false;
|
|
718
|
+
console.log('Server has been stopped.');
|
|
704
719
|
}
|
|
705
|
-
console.log('Server has been stopped.');
|
|
706
720
|
// Notify the callback.
|
|
707
721
|
if (callback) {
|
|
708
722
|
callback(true);
|