tinny-backend 1.0.0

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.
Files changed (86) hide show
  1. package/README.md +207 -0
  2. package/dist/admin/auth.d.ts +2 -0
  3. package/dist/admin/auth.d.ts.map +1 -0
  4. package/dist/admin/auth.js +2 -0
  5. package/dist/admin/auth.js.map +1 -0
  6. package/dist/admin/monitor.d.ts +2 -0
  7. package/dist/admin/monitor.d.ts.map +1 -0
  8. package/dist/admin/monitor.js +2 -0
  9. package/dist/admin/monitor.js.map +1 -0
  10. package/dist/admin/routes.d.ts +2 -0
  11. package/dist/admin/routes.d.ts.map +1 -0
  12. package/dist/admin/routes.js +2 -0
  13. package/dist/admin/routes.js.map +1 -0
  14. package/dist/app/index.d.ts +2 -0
  15. package/dist/app/index.d.ts.map +1 -0
  16. package/dist/app/index.js +19 -0
  17. package/dist/app/index.js.map +1 -0
  18. package/dist/core/Request.d.ts +4 -0
  19. package/dist/core/Request.d.ts.map +1 -0
  20. package/dist/core/Request.js +24 -0
  21. package/dist/core/Request.js.map +1 -0
  22. package/dist/core/Response.d.ts +4 -0
  23. package/dist/core/Response.d.ts.map +1 -0
  24. package/dist/core/Response.js +78 -0
  25. package/dist/core/Response.js.map +1 -0
  26. package/dist/core/Server.d.ts +30 -0
  27. package/dist/core/Server.d.ts.map +1 -0
  28. package/dist/core/Server.js +533 -0
  29. package/dist/core/Server.js.map +1 -0
  30. package/dist/core/types.d.ts +89 -0
  31. package/dist/core/types.d.ts.map +1 -0
  32. package/dist/core/types.js +3 -0
  33. package/dist/core/types.js.map +1 -0
  34. package/dist/examples/example.d.ts +2 -0
  35. package/dist/examples/example.d.ts.map +1 -0
  36. package/dist/examples/example.js +11 -0
  37. package/dist/examples/example.js.map +1 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +11 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/server.d.ts +127 -0
  43. package/dist/server.d.ts.map +1 -0
  44. package/dist/server.js +625 -0
  45. package/dist/server.js.map +1 -0
  46. package/dist/src/admin/auth.d.ts +13 -0
  47. package/dist/src/admin/auth.d.ts.map +1 -0
  48. package/dist/src/admin/auth.js +60 -0
  49. package/dist/src/admin/auth.js.map +1 -0
  50. package/dist/src/admin/monitor.d.ts +3 -0
  51. package/dist/src/admin/monitor.d.ts.map +1 -0
  52. package/dist/src/admin/monitor.js +83 -0
  53. package/dist/src/admin/monitor.js.map +1 -0
  54. package/dist/src/admin/routes.d.ts +14 -0
  55. package/dist/src/admin/routes.d.ts.map +1 -0
  56. package/dist/src/admin/routes.js +150 -0
  57. package/dist/src/admin/routes.js.map +1 -0
  58. package/dist/src/core/Request.d.ts +4 -0
  59. package/dist/src/core/Request.d.ts.map +1 -0
  60. package/dist/src/core/Request.js +24 -0
  61. package/dist/src/core/Request.js.map +1 -0
  62. package/dist/src/core/Response.d.ts +4 -0
  63. package/dist/src/core/Response.d.ts.map +1 -0
  64. package/dist/src/core/Response.js +78 -0
  65. package/dist/src/core/Response.js.map +1 -0
  66. package/dist/src/core/Server.d.ts +34 -0
  67. package/dist/src/core/Server.d.ts.map +1 -0
  68. package/dist/src/core/Server.js +290 -0
  69. package/dist/src/core/Server.js.map +1 -0
  70. package/dist/src/core/types.d.ts +89 -0
  71. package/dist/src/core/types.d.ts.map +1 -0
  72. package/dist/src/core/types.js +3 -0
  73. package/dist/src/core/types.js.map +1 -0
  74. package/dist/src/index.d.ts +16 -0
  75. package/dist/src/index.d.ts.map +1 -0
  76. package/dist/src/index.js +17 -0
  77. package/dist/src/index.js.map +1 -0
  78. package/dist/src/utils/constants.d.ts +12 -0
  79. package/dist/src/utils/constants.d.ts.map +1 -0
  80. package/dist/src/utils/constants.js +12 -0
  81. package/dist/src/utils/constants.js.map +1 -0
  82. package/dist/utils/constants.d.ts +12 -0
  83. package/dist/utils/constants.d.ts.map +1 -0
  84. package/dist/utils/constants.js +12 -0
  85. package/dist/utils/constants.js.map +1 -0
  86. package/package.json +89 -0
@@ -0,0 +1,290 @@
1
+ import { colors } from "../utils/constants.js";
2
+ import { randomBytes } from "crypto";
3
+ import fs from "fs";
4
+ import path, { join } from "path";
5
+ import * as http from "http";
6
+ import * as net from "net";
7
+ import { fileURLToPath } from 'url';
8
+ import { readdir } from 'node:fs/promises';
9
+ import RequestParser from "./Request.js";
10
+ import ResponseParser from "./Response.js";
11
+ import monitor from "../admin/monitor.js";
12
+ export default class Server {
13
+ PORT;
14
+ hostname;
15
+ methodHandler;
16
+ decorators;
17
+ server;
18
+ sessions;
19
+ uptime;
20
+ reqCount;
21
+ logs;
22
+ ServerName;
23
+ defaultHandler;
24
+ getMethodHandlers() {
25
+ return this.methodHandler;
26
+ }
27
+ getDecorators() {
28
+ return this.decorators;
29
+ }
30
+ getUpTime() {
31
+ return this.uptime;
32
+ }
33
+ getReqCount() {
34
+ return this.reqCount;
35
+ }
36
+ getLogs() {
37
+ return this.logs;
38
+ }
39
+ generateKey() {
40
+ return randomBytes(16).toString('hex');
41
+ }
42
+ generateSession(ip) {
43
+ const session = {
44
+ ip,
45
+ lastReq: Date.now(),
46
+ reqCount: 0,
47
+ key: this.generateKey(),
48
+ banInterval: 60000
49
+ };
50
+ this.sessions.push(session);
51
+ return session;
52
+ }
53
+ getSession(ip) {
54
+ return this.sessions.filter((ses) => ses.ip === ip)[0];
55
+ }
56
+ getHost() {
57
+ return this.hostname;
58
+ }
59
+ getPort() {
60
+ return this.PORT;
61
+ }
62
+ add(opt) {
63
+ const newPath = opt.path.replace(/(?<=.)\/+$/, "");
64
+ const paramNames = [];
65
+ const parsedPath = newPath.replace(/:([^\/]+)/g, (_, paramName) => {
66
+ paramNames.push(paramName);
67
+ return "([^/]+)";
68
+ });
69
+ this.methodHandler.push({
70
+ method: opt.method,
71
+ handler: opt.handler,
72
+ regex: new RegExp(`^${parsedPath}$`),
73
+ path: newPath,
74
+ paramNames,
75
+ middelWares: opt.middelWares,
76
+ next: opt.next
77
+ });
78
+ this.log(`Setting a handler for ${opt.method} ${this.hostname}:${this.PORT}${opt.path.replace(/(?<=.)\/+$/, "")} [${opt.path.replace(/(?<=.)\/+$/, "")}]`);
79
+ }
80
+ decorate(name, data) {
81
+ this.decorators.push({
82
+ name,
83
+ data
84
+ });
85
+ }
86
+ useDecorator(name) {
87
+ if (this.decorators.length == 0)
88
+ return null;
89
+ return this.decorators.filter((dec) => dec.name === name)[0];
90
+ }
91
+ async readDir(DIR, prefix) {
92
+ try {
93
+ const entries = await readdir(DIR, { recursive: true, withFileTypes: true });
94
+ const result = { files: [] };
95
+ for (const entry of entries)
96
+ if (!entry.isDirectory())
97
+ result.files.push({ FileName: join(entry.parentPath, entry.name), prefix: join(prefix, entry.name) });
98
+ return result;
99
+ }
100
+ catch (error) {
101
+ this.log(`Error reading directory: ${DIR} error ${error}`, "error");
102
+ }
103
+ return null;
104
+ }
105
+ async servDir(DIR, pref, middelWares) {
106
+ let files = null;
107
+ try {
108
+ files = await this.readDir(DIR, pref);
109
+ }
110
+ catch {
111
+ this.log("an error happens when try to server a dir", "error");
112
+ }
113
+ if (!files) {
114
+ this.log("Failed to serve this dir", "error");
115
+ return;
116
+ }
117
+ let index = false;
118
+ for (let i = 0; i < files.files.length; i++) {
119
+ const filename = files.files[i]?.FileName.replace(/^\/+/, "/");
120
+ const prefix = files.files[i]?.prefix.replace(/^\/+/, "/");
121
+ if (!filename || !prefix)
122
+ break;
123
+ if ((path.basename(filename).startsWith("index") && path.dirname(filename) == DIR.replace(/\.\//g, '')) && !index) {
124
+ this.log(`setting ${filename} as default page for ${DIR}`);
125
+ this.add({
126
+ method: "GET",
127
+ path: `/${path.dirname(prefix)}`,
128
+ handler: (req, res) => {
129
+ this.SendFile(res, filename, 200);
130
+ return;
131
+ },
132
+ middelWares
133
+ });
134
+ index = true;
135
+ }
136
+ this.add({
137
+ method: "GET",
138
+ path: `/${prefix}`,
139
+ handler: async (req, res) => {
140
+ await this.SendFile(res, filename, 200);
141
+ return;
142
+ },
143
+ middelWares
144
+ });
145
+ }
146
+ if (!index) {
147
+ this.add({
148
+ method: "GET",
149
+ path: `/${pref}`,
150
+ handler: async (req, res) => {
151
+ res.send(200, {
152
+ ...files.files.map((file) => {
153
+ return {
154
+ "name": path.basename(file.FileName),
155
+ "url": `http://${this.hostname}:${this.PORT}/${file.prefix}`
156
+ };
157
+ })
158
+ });
159
+ },
160
+ middelWares
161
+ });
162
+ }
163
+ }
164
+ async SendFile(res, FILE, status) {
165
+ const __filename = fileURLToPath(import.meta.url);
166
+ const projectRoot = path.resolve(__filename, '..', '..');
167
+ const __dirname = projectRoot;
168
+ const extName = String(path.extname(FILE)).toLowerCase();
169
+ const mimeTypes = {
170
+ '.txt': 'text/plain',
171
+ '.html': 'text/html',
172
+ '.css': 'text/css',
173
+ '.js': 'text/javascript',
174
+ '.png': 'image/png',
175
+ '.jpg': 'image/jpeg',
176
+ '.json': 'application/json',
177
+ '.mp4': 'video/mp4',
178
+ '.webm': 'video/webm',
179
+ '.ogg': 'video/ogg',
180
+ '.avi': 'video/x-msvideo'
181
+ };
182
+ const contentType = mimeTypes[extName] || 'application/octet-stream';
183
+ try {
184
+ await fs.promises.access(`./${FILE}`, fs.constants.F_OK);
185
+ res.server.log(`sending file ${FILE} to ${res.ip}`, (status == 404 || status == 401) ? "error" : "message");
186
+ return res.sendFile(status, contentType, { PATH: `./${FILE}` });
187
+ }
188
+ catch (err) {
189
+ console.log(err);
190
+ const errorPagePath = path.join(__dirname, 'public', 'stauts/404.html');
191
+ res.server.log(`cannot find ${FILE} to send to ${res.ip}`, "error");
192
+ return res.sendFile(404, 'text/html', { PATH: errorPagePath });
193
+ }
194
+ }
195
+ log(message, type) {
196
+ const DateObj = new Date();
197
+ const date = `${DateObj.toDateString() + " " + DateObj.toLocaleTimeString()}`;
198
+ const newType = type ?? message;
199
+ console.log(`[${colors.green}${date}${colors.reset}]`, `[${colors.yellow}${this.ServerName}${colors.reset}] =>`, `${(type == "error" ? colors.red : colors.white)}${message}${colors.reset}`);
200
+ if (this.logs.length > 100)
201
+ this.logs.shift();
202
+ this.logs.push({
203
+ message,
204
+ type: type ?? "message",
205
+ date
206
+ });
207
+ }
208
+ constructor(args) {
209
+ this.sessions = [];
210
+ this.decorators = [];
211
+ this.methodHandler = [];
212
+ this.hostname = args.hostname ?? "localhost";
213
+ this.PORT = args.port ?? 3000;
214
+ this.uptime = Date.now();
215
+ this.reqCount = 0;
216
+ this.logs = [];
217
+ this.ServerName = args.ServerName ?? "Server";
218
+ this.defaultHandler = args.DefaultHandler ?? (async (req, res) => {
219
+ this.log(`Sending defualt of this route ${req.ReqUrl?.pathname}`);
220
+ await this.SendFile(res, "public/status/404.html", 404);
221
+ });
222
+ this.server = http.createServer((req, res) => {
223
+ let body = "";
224
+ this.reqCount++;
225
+ const Req = RequestParser(req, this);
226
+ const Res = ResponseParser(res, Req, this);
227
+ req.on("data", (chunk) => {
228
+ body += chunk.toString();
229
+ });
230
+ req.on("end", async () => {
231
+ Req.body = body ? JSON.parse(body) : null;
232
+ body = "";
233
+ let handlersCount = 0;
234
+ for (let i = 0; i < this.methodHandler.length; i++) {
235
+ const match = Req.ReqUrl?.pathname.match(this.methodHandler[i]?.regex ?? "");
236
+ if (this.methodHandler[i]?.method == req.method
237
+ && match) {
238
+ Req.params = {};
239
+ this.methodHandler[i]?.paramNames.forEach((name, index) => {
240
+ Req.params[name] = match[index + 1] || "";
241
+ });
242
+ if (!Res.isClosed) {
243
+ if (this.methodHandler[i]?.middelWares && typeof this.methodHandler[i]?.middelWares != "undefined") {
244
+ for (const middelware of this.methodHandler[i]?.middelWares ?? []) {
245
+ await middelware(Req, Res);
246
+ if (Res.isClosed)
247
+ break;
248
+ }
249
+ }
250
+ if (!Res.isClosed)
251
+ await this.methodHandler[i]?.handler(req, res);
252
+ const nextFn = this.methodHandler[i]?.next;
253
+ if (typeof nextFn === "function")
254
+ await nextFn(Req, Res);
255
+ handlersCount++;
256
+ }
257
+ }
258
+ }
259
+ if (!handlersCount) {
260
+ this.defaultHandler(Req, Res);
261
+ }
262
+ });
263
+ });
264
+ this.server.on("connection", (socket) => {
265
+ const IP = socket.remoteAddress?.replace(/^.*:/, '') ?? "INVALID IP";
266
+ const RPORT = socket.remotePort ?? this.PORT;
267
+ this.log(`New connention recieved ip ${IP} on port ${RPORT}`);
268
+ socket.on("close", (hadError) => {
269
+ this.log(`Client has drop the connection ${IP}`, hadError ? "error" : "message");
270
+ });
271
+ socket.on("error", (err) => {
272
+ this.log(`Connection failed with ${IP}, cause : ${err.message}`, "error");
273
+ });
274
+ });
275
+ this.server.on("close", () => {
276
+ this.log(`Server has successfully stopped accepting connections`);
277
+ });
278
+ this.server.on("error", (err) => {
279
+ this.log(err.message, "error");
280
+ });
281
+ }
282
+ listen(enableMon, callback) {
283
+ if (enableMon)
284
+ monitor(new Server({ port: this.PORT + 1, ServerName: "Monitor" }));
285
+ this.server.listen(this.PORT, callback ?? (() => {
286
+ this.log(`start listening in http://${this.hostname}:${this.PORT}`);
287
+ }));
288
+ }
289
+ }
290
+ //# sourceMappingURL=Server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../src/core/Server.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,aAAa,MAAM,cAAc,CAAC;AACzC,OAAO,cAAc,MAAM,eAAe,CAAC;AAC3C,OAAO,OAAO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AC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,SAAmB,EAAE,QAAqB;QAC7C,IAAI,SAAS;YACT,OAAO,CAAC,IAAI,MAAM,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,UAAU,EAAE,SAAS,EAAC,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,IAAI,CAAC,GAAE,EAAE;YAC3C,IAAI,CAAC,GAAG,CAAC,6BAA6B,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QACvE,CAAC,CAAC,CAAC,CAAA;IACP,CAAC;CACJ"}
@@ -0,0 +1,89 @@
1
+ import * as http from "http";
2
+ import Server from "./Server.js";
3
+ export type HandlerFun = (req: ServerReq, res: ServerRes) => void | Promise<void>;
4
+ export type AddOption = {
5
+ method: Methods;
6
+ path: string;
7
+ handler: HandlerFun;
8
+ middelWares?: HandlerFun[] | undefined;
9
+ next?: HandlerFun;
10
+ };
11
+ export type Logs = {
12
+ message: string;
13
+ type: "message" | "error";
14
+ date: string;
15
+ };
16
+ export type Headers = {
17
+ key: string;
18
+ value: string;
19
+ };
20
+ export type Cookie = {
21
+ key: string;
22
+ value: string;
23
+ };
24
+ export type ServerOptions = {
25
+ port?: number;
26
+ hostname?: string;
27
+ reqPerMinute?: number;
28
+ DefaultHandler?: HandlerFun;
29
+ ServerName?: string;
30
+ };
31
+ export type ServerReq = http.IncomingMessage & {
32
+ ReqUrl: URL | null;
33
+ Query: URLSearchParams;
34
+ queries: object;
35
+ body?: any;
36
+ ip: string;
37
+ server: Server;
38
+ params: Record<string, string>;
39
+ };
40
+ export type ServFiles = {
41
+ FileName: string;
42
+ prefix: string;
43
+ };
44
+ export type DirFiles = {
45
+ files: ServFiles[];
46
+ };
47
+ export type ServerRes = http.ServerResponse & {
48
+ body?: any;
49
+ ip: string;
50
+ send: (status: number, data?: any, headers?: object) => void;
51
+ sendFile: (status: number, ContentType: string, data?: any, headers?: object) => void;
52
+ isClosed: boolean;
53
+ server: Server;
54
+ coockie: (key: string, value: string) => string;
55
+ getAllCookies: () => string[];
56
+ setCookie: (name: string, value: string) => void;
57
+ getCookie: (name: string) => Cookie | null;
58
+ addCookie: (name: string, value: string) => void;
59
+ };
60
+ export type Methods = "POST" | "GET" | "PUT" | "DELETE";
61
+ export type Handlers = {
62
+ method: Methods;
63
+ path: string;
64
+ paramNames: string[];
65
+ handler: Function;
66
+ regex: RegExp;
67
+ middelWares?: HandlerFun[] | undefined;
68
+ next?: HandlerFun | undefined;
69
+ };
70
+ export type Decorator = {
71
+ name: string;
72
+ data: any;
73
+ };
74
+ export type Session = {
75
+ ip: string;
76
+ lastReq: number;
77
+ reqCount: number;
78
+ key: string;
79
+ banInterval: number;
80
+ };
81
+ export type AdminSessions = {
82
+ id: string;
83
+ ip: string;
84
+ userAgent: string;
85
+ creation: number;
86
+ isValid: boolean;
87
+ request: number;
88
+ };
89
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAA;AAGhC,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,KAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE/E,MAAM,MAAM,SAAS,GAAG;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;IACvC,IAAI,CAAC,EAAE,UAAU,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,IAAI,GAAG;IACf,OAAO,EAAE,MAAM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AM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import * as http from "http";
2
+ import Server from "./Server.js";
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAA"}
@@ -0,0 +1,16 @@
1
+ export { default as Server } from './core/Server.js';
2
+ export { default as TinnyServer } from './core/Server.js';
3
+ export type { ServerOptions, ServerReq, ServerRes, AddOption, HandlerFun, Methods, Headers, Cookie, Logs, Session, AdminSessions, Decorator, DirFiles, ServFiles } from './core/types.js';
4
+ export declare const VERSION = "1.0.0";
5
+ export declare const NAME = "tinny-backend";
6
+ import Server from './core/Server.js';
7
+ export default Server;
8
+ export declare function createServer(options?: import('./core/types.js').ServerOptions): Server;
9
+ export declare const packageInfo: {
10
+ name: string;
11
+ version: string;
12
+ description: string;
13
+ homepage: string;
14
+ bugs: string;
15
+ };
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE1D,YAAY,EACR,aAAa,EACb,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,OAAO,EACP,OAAO,EACP,MAAM,EACN,IAAI,EACJ,OAAO,EACP,aAAa,EACb,SAAS,EACT,QAAQ,EACR,SAAS,EACZ,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,IAAI,kBAAkB,CAAC;AAGpC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,eAAe,MAAM,CAAC;AAEtB,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,iBAAiB,EAAE,aAAa,GAAG,MAAM,CAEtF;AAED,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAC"}
@@ -0,0 +1,17 @@
1
+ export { default as Server } from './core/Server.js';
2
+ export { default as TinnyServer } from './core/Server.js';
3
+ export const VERSION = '1.0.0';
4
+ export const NAME = 'tinny-backend';
5
+ import Server from './core/Server.js';
6
+ export default Server;
7
+ export function createServer(options) {
8
+ return new Server(options || {});
9
+ }
10
+ export const packageInfo = {
11
+ name: NAME,
12
+ version: VERSION,
13
+ description: 'A lightweight Node.js HTTP server framework',
14
+ homepage: 'https://github.com/iaceene/tinny-backend',
15
+ bugs: 'https://github.com/iaceene/tinny-backend/issues'
16
+ };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAmB1D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAG,eAAe,CAAC;AAGpC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,eAAe,MAAM,CAAC;AAEtB,MAAM,UAAU,YAAY,CAAC,OAAiD;IAC1E,OAAO,IAAI,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,6CAA6C;IAC1D,QAAQ,EAAE,0CAA0C;IACpD,IAAI,EAAE,iDAAiD;CAC1D,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const colors: {
2
+ reset: string;
3
+ black: string;
4
+ red: string;
5
+ green: string;
6
+ yellow: string;
7
+ blue: string;
8
+ magenta: string;
9
+ cyan: string;
10
+ white: string;
11
+ };
12
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;CAUlB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const colors = {
2
+ reset: '\x1b[0m',
3
+ black: '\x1b[30m',
4
+ red: '\x1b[31m',
5
+ green: '\x1b[32m',
6
+ yellow: '\x1b[33m',
7
+ blue: '\x1b[34m',
8
+ magenta: '\x1b[35m',
9
+ cyan: '\x1b[36m',
10
+ white: '\x1b[37m',
11
+ };
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;CACpB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const colors: {
2
+ reset: string;
3
+ black: string;
4
+ red: string;
5
+ green: string;
6
+ yellow: string;
7
+ blue: string;
8
+ magenta: string;
9
+ cyan: string;
10
+ white: string;
11
+ };
12
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;CAUlB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const colors = {
2
+ reset: '\x1b[0m',
3
+ black: '\x1b[30m',
4
+ red: '\x1b[31m',
5
+ green: '\x1b[32m',
6
+ yellow: '\x1b[33m',
7
+ blue: '\x1b[34m',
8
+ magenta: '\x1b[35m',
9
+ cyan: '\x1b[36m',
10
+ white: '\x1b[37m',
11
+ };
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;CACpB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "tinny-backend",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight and flexible routing system for Node.js with WebSocket support",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Yassine Ajagrou",
8
+ "email": "yassineajagrou8@gmail.com",
9
+ "url": "https://github.com/iaceene"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/iaceene/TinnyBackend.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/iaceene/TinnyBackend/issues"
17
+ },
18
+ "homepage": "https://github.com/iaceene/TinnyBackend#readme",
19
+ "keywords": [
20
+ "router",
21
+ "routing",
22
+ "express",
23
+ "websocket",
24
+ "ws",
25
+ "nodejs",
26
+ "typescript",
27
+ "jwt",
28
+ "authentication"
29
+ ],
30
+ "type": "module",
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "import": "./dist/index.js",
37
+ "require": "./dist/index.js",
38
+ "types": "./dist/index.d.ts"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE",
45
+ "CHANGELOG.md"
46
+ ],
47
+ "scripts": {
48
+ "build": "tsc",
49
+ "dev": "nodemon --exec tsx src/app/index.ts",
50
+ "example": "node ./dist/app/index.js",
51
+ "test": "vitest",
52
+ "test:coverage": "vitest --coverage",
53
+ "lint": "eslint . --ext .ts",
54
+ "lint:fix": "eslint . --ext .ts --fix",
55
+ "format": "prettier --write .",
56
+ "prepublishOnly": "npm run build",
57
+ "version": "npm run format && git add -A src",
58
+ "postversion": "git push && git push --tags"
59
+ },
60
+ "peerDependencies": {
61
+ "node": ">=18.0.0"
62
+ },
63
+ "devDependencies": {
64
+ "@types/jsonwebtoken": "^9.0.10",
65
+ "@types/node": "^25.9.3",
66
+ "@types/ws": "^8.18.1",
67
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
68
+ "@typescript-eslint/parser": "^7.0.0",
69
+ "eslint": "^8.57.0",
70
+ "nodemon": "^3.1.14",
71
+ "prettier": "^3.2.5",
72
+ "tsx": "^4.7.0",
73
+ "typescript": "^5.7.3",
74
+ "vitest": "^4.1.9"
75
+ },
76
+ "dependencies": {
77
+ "dotenv": "^17.4.2",
78
+ "jsonwebtoken": "^9.0.3",
79
+ "ws": "^8.21.0"
80
+ },
81
+ "engines": {
82
+ "node": ">=18.0.0"
83
+ },
84
+ "publishConfig": {
85
+ "access": "public",
86
+ "registry": "https://registry.npmjs.org/"
87
+ },
88
+ "private": false
89
+ }