slower 1.1.20 → 1.1.21

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 ADDED
@@ -0,0 +1,22 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Tomás Luchesi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/lib/router.js CHANGED
@@ -409,16 +409,16 @@ class SlowerRouter {
409
409
  ) {
410
410
  i = routes.length;
411
411
  route.callback(req, res);
412
- if (res.writableEnded) return; // if res.end() was called
413
- else res.end(); // if res.end() was not called
412
+ // if (res.writableEnded) return; // if res.end() was called
413
+ // else res.end(); // if res.end() was not called
414
414
  return;
415
415
  }
416
416
  }
417
417
  fallback(req,res);
418
- if (!res.writableEnded) res.end(); // No need to call res.end() on handlers anymore
418
+ if (!res.writableEnded) res.end();
419
419
  } else {
420
420
  blockedMethodCallback(req, res);
421
- if (!res.writableEnded) res.end(); // No need to call res.end() on handlers anymore
421
+ if (!res.writableEnded) res.end();
422
422
  }
423
423
  } catch(err) {
424
424
  console.log(err);
package/lib/utils.js CHANGED
@@ -90,10 +90,17 @@ const setResponseAssessors = (resSocket) => {
90
90
  resSocket.sendText = (data, code = 200) => {
91
91
  resSocket.writeHead(code, { 'Content-Type': 'text/plain' });
92
92
  resSocket.write(data);
93
+ resSocket.end();
93
94
  };
94
95
  resSocket.sendJSON = (data, code = 200) => {
95
96
  resSocket.writeHead(code, { 'Content-Type': 'application/json' });
97
+ resSocket.write(typeof data === 'string' ? data : JSON.stringify(data));
98
+ resSocket.end();
99
+ };
100
+ resSocket.sendHTML = (data, code = 200) => {
101
+ resSocket.writeHead(code, { 'Content-Type': 'text/html' });
96
102
  resSocket.write(data);
103
+ resSocket.end();
97
104
  };
98
105
  }
99
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slower",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "description": "A package for simple HTTP server routing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -10,6 +10,6 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
12
  "keywords": [],
13
- "author": "no.mad.devtech@gmail.com",
14
- "license": "ISC"
13
+ "author": "Tomás Luchesi <no.mad.devtech@gmail.com>",
14
+ "license": "MIT"
15
15
  }
package/readme.md CHANGED
@@ -146,8 +146,7 @@ app.setDynamic('/download/{?}/', './main-download.txt', { DowloadName: generateD
146
146
  // Responds to download routes such as '/download/2/'
147
147
 
148
148
  app.setFallback((req, res) => {
149
- res.writeHead(200, { 'Content-Type': 'text/html' });
150
- res.write('<html><body><p>This is the fallback page.</p></body></html>');
149
+ res.sendHTML('<html><body><p>This is the fallback page.</p></body></html>', 404);
151
150
  res.end();
152
151
  });
153
152