tinny-backend 1.0.6 → 1.0.8

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.
@@ -1,4 +1,5 @@
1
1
  import type { ServerOptions, ServerRes, Handlers, AddOption, HandlerFun, Decorator, Logs, DirFiles } from "./types.js";
2
+ import * as http from "http";
2
3
  export default class Server {
3
4
  private PORT;
4
5
  private hostname;
@@ -11,11 +12,15 @@ export default class Server {
11
12
  private logs;
12
13
  private ServerName;
13
14
  private defaultHandler;
15
+ private Wss;
14
16
  getMethodHandlers(): Handlers[];
17
+ getHttpServer(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
15
18
  getDecorators(): Decorator[];
16
19
  getUpTime(): number;
17
20
  getReqCount(): number;
18
21
  getLogs(): Logs[];
22
+ createWsServer(): this;
23
+ getWsServer(): import("ws").WebSocketServer;
19
24
  private generateKey;
20
25
  private generateSession;
21
26
  private getSession;
@@ -8,6 +8,7 @@ import { fileURLToPath } from 'url';
8
8
  import { readdir } from 'node:fs/promises';
9
9
  import RequestParser from "./Request.js";
10
10
  import ResponseParser from "./Response.js";
11
+ import { TinnyWs } from "./Websocket.js";
11
12
  export default class Server {
12
13
  PORT;
13
14
  hostname;
@@ -20,9 +21,13 @@ export default class Server {
20
21
  logs;
21
22
  ServerName;
22
23
  defaultHandler;
24
+ Wss = null;
23
25
  getMethodHandlers() {
24
26
  return this.methodHandler;
25
27
  }
28
+ getHttpServer() {
29
+ return this.server;
30
+ }
26
31
  getDecorators() {
27
32
  return this.decorators;
28
33
  }
@@ -35,6 +40,17 @@ export default class Server {
35
40
  getLogs() {
36
41
  return this.logs;
37
42
  }
43
+ createWsServer() {
44
+ if (!this.Wss)
45
+ this.Wss = new TinnyWs(this);
46
+ return this;
47
+ }
48
+ getWsServer() {
49
+ if (this.Wss)
50
+ return this.Wss.getWss();
51
+ this.Wss = new TinnyWs(this);
52
+ return this.Wss.getWss();
53
+ }
38
54
  generateKey() {
39
55
  return randomBytes(16).toString('hex');
40
56
  }
@@ -0,0 +1,7 @@
1
+ import { WebSocketServer } from 'ws';
2
+ import type Server from './Server.js';
3
+ export declare class TinnyWs {
4
+ private wss;
5
+ constructor(server: Server);
6
+ getWss(): WebSocketServer;
7
+ }
@@ -0,0 +1,14 @@
1
+ import { WebSocketServer } from 'ws';
2
+ export class TinnyWs {
3
+ wss;
4
+ constructor(server) {
5
+ this.wss = new WebSocketServer({ server: server.getHttpServer() });
6
+ this.wss.on("error", (error) => {
7
+ server.log(`WS: ${error.message}`, "error");
8
+ });
9
+ return this;
10
+ }
11
+ getWss() {
12
+ return this.wss;
13
+ }
14
+ }
@@ -1 +1 @@
1
- export declare const VERSION = "1.0.6";
1
+ export declare const VERSION = "1.0.8";
@@ -1 +1 @@
1
- export const VERSION = "1.0.6";
1
+ export const VERSION = "1.0.8";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinny-backend",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A lightweight and flexible backend framework built on Node.js.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -45,6 +45,7 @@
45
45
  "scripts": {
46
46
  "build": "tsc",
47
47
  "dev": "tsx src/index.ts",
48
+ "test-ws": "tsx src/test/ws.test.ts",
48
49
  "test": "vitest",
49
50
  "lint": "eslint . --ext .ts",
50
51
  "lint:fix": "eslint . --ext .ts --fix",
@@ -53,6 +54,7 @@
53
54
  },
54
55
  "devDependencies": {
55
56
  "@types/node": "^25.9.3",
57
+ "@types/ws": "^8.18.1",
56
58
  "@typescript-eslint/eslint-plugin": "^8.39.1",
57
59
  "@typescript-eslint/parser": "^8.39.1",
58
60
  "eslint": "^9.36.0",
@@ -62,10 +64,13 @@
62
64
  "vitest": "^4.1.9"
63
65
  },
64
66
  "engines": {
65
- "node": ">=18.0.0"
67
+ "node": ">=24.13.1"
66
68
  },
67
69
  "publishConfig": {
68
70
  "access": "public"
69
71
  },
70
- "private": false
71
- }
72
+ "private": false,
73
+ "dependencies": {
74
+ "ws": "^8.21.3"
75
+ }
76
+ }
package/dist/tester.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/tester.js DELETED
@@ -1,10 +0,0 @@
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();