tinny-backend 1.0.8 → 1.0.9

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.
@@ -12,6 +12,7 @@ export default class Server {
12
12
  private logs;
13
13
  private ServerName;
14
14
  private defaultHandler;
15
+ private golobalMidellWare;
15
16
  private Wss;
16
17
  getMethodHandlers(): Handlers[];
17
18
  getHttpServer(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
@@ -26,6 +27,7 @@ export default class Server {
26
27
  private getSession;
27
28
  getHost(): string;
28
29
  getPort(): number;
30
+ use(fun: HandlerFun): void;
29
31
  add(opt: AddOption): void;
30
32
  decorate(name: string, data: any): void;
31
33
  useDecorator(name: string): Decorator | null | undefined;
@@ -21,6 +21,7 @@ export default class Server {
21
21
  logs;
22
22
  ServerName;
23
23
  defaultHandler;
24
+ golobalMidellWare;
24
25
  Wss = null;
25
26
  getMethodHandlers() {
26
27
  return this.methodHandler;
@@ -74,6 +75,9 @@ export default class Server {
74
75
  getPort() {
75
76
  return this.PORT;
76
77
  }
78
+ use(fun) {
79
+ this.golobalMidellWare.push({ handler: fun });
80
+ }
77
81
  add(opt) {
78
82
  const newPath = opt.path.replace(/(?<=.)\/+$/, "");
79
83
  const paramNames = [];
@@ -220,6 +224,7 @@ export default class Server {
220
224
  });
221
225
  }
222
226
  constructor(args) {
227
+ this.golobalMidellWare = [];
223
228
  this.sessions = [];
224
229
  this.decorators = [];
225
230
  this.methodHandler = [];
@@ -251,6 +256,13 @@ export default class Server {
251
256
  Req.body = body;
252
257
  body = "";
253
258
  let handlersCount = 0;
259
+ for (const fun of this.golobalMidellWare) {
260
+ await fun.handler(req, res);
261
+ if (res.writableEnded) {
262
+ handlersCount++;
263
+ break;
264
+ }
265
+ }
254
266
  for (let i = 0; i < this.methodHandler.length; i++) {
255
267
  const match = Req.ReqUrl?.pathname.match(this.methodHandler[i]?.regex ?? "");
256
268
  if (this.methodHandler[i]?.method == req.method
@@ -21,6 +21,9 @@ export type Cookie = {
21
21
  key: string;
22
22
  value: string;
23
23
  };
24
+ export type GolobalMidellWare = {
25
+ handler: HandlerFun;
26
+ };
24
27
  export type ServerOptions = {
25
28
  port?: number;
26
29
  hostname?: string;
@@ -1 +1 @@
1
- export declare const VERSION = "1.0.8";
1
+ export declare const VERSION = "1.0.9";
@@ -1 +1 @@
1
- export const VERSION = "1.0.8";
1
+ export const VERSION = "1.0.9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinny-backend",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A lightweight and flexible backend framework built on Node.js.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -46,6 +46,7 @@
46
46
  "build": "tsc",
47
47
  "dev": "tsx src/index.ts",
48
48
  "test-ws": "tsx src/test/ws.test.ts",
49
+ "test-use": "tsx src/test/use.test.ts",
49
50
  "test": "vitest",
50
51
  "lint": "eslint . --ext .ts",
51
52
  "lint:fix": "eslint . --ext .ts --fix",