basic-node-server 1.0.8 → 1.0.10
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 -15
- package/bns.js +7 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,31 +2,27 @@
|
|
|
2
2
|
Basic node server for everyone.
|
|
3
3
|
|
|
4
4
|
Basic node server simply hosts and serves files from the current project directory through HTTP.
|
|
5
|
-
If no path is given, it will serve the index.html file.
|
|
5
|
+
If no path is given, it will serve the index.html file in the root directory.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
6
8
|
|
|
7
|
-
## How to use
|
|
8
9
|
```
|
|
9
|
-
|
|
10
|
+
npm install basic-node-server
|
|
11
|
+
|
|
10
12
|
```
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
## Usage
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Then, you can run it from your project directory:
|
|
15
17
|
|
|
16
18
|
```
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## NPM
|
|
21
|
-
This package is also available on NPM. To install it, run:
|
|
22
|
-
|
|
19
|
+
npx bns [port]
|
|
23
20
|
```
|
|
24
|
-
npm install basic-node-server
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
The [port] argument is optional. If no port is given, it will default to 3000.
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
For example, if you want to serve the current directory on port 8080, you would run:
|
|
29
25
|
|
|
30
26
|
```
|
|
31
|
-
node
|
|
27
|
+
node bns 8080
|
|
32
28
|
```
|
package/bns.js
CHANGED
|
@@ -25,11 +25,17 @@ const server = http.createServer((req, res) => {
|
|
|
25
25
|
// Extract the file path from the request URL
|
|
26
26
|
let filePath = path.join(process.cwd(), req.url);
|
|
27
27
|
|
|
28
|
+
// check if its a get request
|
|
29
|
+
if (req.method !== 'GET') {
|
|
30
|
+
res.statusCode = 405;
|
|
31
|
+
res.end('Method not allowed');
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
// remove get query string
|
|
29
35
|
filePath = filePath.split('?')[0];
|
|
30
36
|
|
|
31
37
|
// If filePath is empty or ends with '/', default to 'index.html'
|
|
32
|
-
if (!filePath || filePath.endsWith('/')) {
|
|
38
|
+
if (!filePath || filePath.endsWith('/') || filePath.endsWith('\\')) {
|
|
33
39
|
filePath = path.join(filePath, 'index.html');
|
|
34
40
|
}
|
|
35
41
|
|