tinny-backend 1.0.3 → 1.0.4

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.
@@ -13,7 +13,10 @@ export default function RequestParser(req, server) {
13
13
  req.ReqUrl.pathname = req.url;
14
14
  req.queries = {};
15
15
  }
16
- req.ip = req.socket.remoteAddress?.split(':').pop() ?? "DEVICE IP";
16
+ req.ip = req.headers["x-forwarded-for"]?.toString().split(",")[0]?.trim()
17
+ || req.headers["x-real-ip"]?.toString()
18
+ || req.socket.remoteAddress?.split(':').pop()
19
+ || "UNKNOWN_IP";
17
20
  req.server = server;
18
21
  server.log(`${req.ip} requested METHOD ${req.method}, PATH ${req.ReqUrl?.pathname}`);
19
22
  req.on("data", (chunk) => {
@@ -226,7 +226,9 @@ export default class Server {
226
226
  body += chunk.toString();
227
227
  });
228
228
  req.on("end", async () => {
229
- Req.body = body ? JSON.parse(body) : null;
229
+ if (req.headers["content-type"] === "application/json") {
230
+ Req.body = body ? JSON.parse(body) : null;
231
+ }
230
232
  body = "";
231
233
  let handlersCount = 0;
232
234
  for (let i = 0; i < this.methodHandler.length; i++) {
@@ -0,0 +1 @@
1
+ export {};
package/dist/tester.js ADDED
@@ -0,0 +1,10 @@
1
+ import Server from "./core/Server.js";
2
+ const srv = new Server({});
3
+ srv.add({
4
+ path: "/",
5
+ method: "POST",
6
+ handler: (req, res) => {
7
+ res.send(200, { message: "Hello" });
8
+ }
9
+ });
10
+ srv.listen();
@@ -1 +1 @@
1
- export declare const VERSION = "1.0.3";
1
+ export declare const VERSION = "1.0.4";
@@ -1 +1 @@
1
- export const VERSION = "1.0.3";
1
+ export const VERSION = "1.0.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinny-backend",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A lightweight and flexible backend framework built on Node.js.",
5
5
  "license": "MIT",
6
6
  "author": {