elit 3.1.3 → 3.1.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.
- package/dist/build.d.mts +1 -1
- package/dist/cli.js +1 -1
- package/dist/{server-BDgmlULi.d.ts → server-9dH1l8MG.d.ts} +8 -3
- package/dist/{server-QfJoaxeO.d.mts → server-jAa9yJM4.d.mts} +8 -3
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +8 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +45 -3
- package/dist/server.mjs +45 -3
- package/dist/types.d.mts +7 -2
- package/package.json +1 -1
- package/src/server.ts +63 -13
package/dist/build.d.mts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1412,7 +1412,7 @@ var require_package = __commonJS({
|
|
|
1412
1412
|
"package.json"(exports2, module2) {
|
|
1413
1413
|
module2.exports = {
|
|
1414
1414
|
name: "elit",
|
|
1415
|
-
version: "3.1.
|
|
1415
|
+
version: "3.1.4",
|
|
1416
1416
|
description: "Optimized lightweight library for creating DOM elements with reactive state",
|
|
1417
1417
|
main: "dist/index.js",
|
|
1418
1418
|
module: "dist/index.mjs",
|
|
@@ -180,7 +180,7 @@ interface BuildResult {
|
|
|
180
180
|
* - Deno: uses Deno.emit
|
|
181
181
|
*/
|
|
182
182
|
|
|
183
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
183
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
|
|
184
184
|
interface ServerRouteContext {
|
|
185
185
|
req: IncomingMessage;
|
|
186
186
|
res: ServerResponse;
|
|
@@ -189,20 +189,25 @@ interface ServerRouteContext {
|
|
|
189
189
|
body: any;
|
|
190
190
|
headers: Record<string, string | string[] | undefined>;
|
|
191
191
|
user?: any;
|
|
192
|
+
send?(data: any): ServerResponse;
|
|
193
|
+
json?(data: any): ServerResponse;
|
|
194
|
+
status?(code: number): ServerResponse;
|
|
192
195
|
}
|
|
193
196
|
type ServerRouteHandler = (ctx: ServerRouteContext, next?: () => Promise<void>) => void | Promise<void>;
|
|
194
197
|
type Middleware = (ctx: ServerRouteContext, next: () => Promise<void>) => void | Promise<void>;
|
|
195
198
|
declare class ServerRouter {
|
|
196
199
|
private routes;
|
|
197
200
|
private middlewares;
|
|
198
|
-
use(
|
|
199
|
-
|
|
201
|
+
use(...args: Array<any>): this;
|
|
202
|
+
all: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
200
203
|
get: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
201
204
|
post: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
202
205
|
put: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
203
206
|
delete: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
204
207
|
patch: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
205
208
|
options: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
209
|
+
head: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
210
|
+
private toMiddleware;
|
|
206
211
|
private addRoute;
|
|
207
212
|
private pathToRegex;
|
|
208
213
|
private parseQuery;
|
|
@@ -180,7 +180,7 @@ interface BuildResult {
|
|
|
180
180
|
* - Deno: uses Deno.emit
|
|
181
181
|
*/
|
|
182
182
|
|
|
183
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
183
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
|
|
184
184
|
interface ServerRouteContext {
|
|
185
185
|
req: IncomingMessage;
|
|
186
186
|
res: ServerResponse;
|
|
@@ -189,20 +189,25 @@ interface ServerRouteContext {
|
|
|
189
189
|
body: any;
|
|
190
190
|
headers: Record<string, string | string[] | undefined>;
|
|
191
191
|
user?: any;
|
|
192
|
+
send?(data: any): ServerResponse;
|
|
193
|
+
json?(data: any): ServerResponse;
|
|
194
|
+
status?(code: number): ServerResponse;
|
|
192
195
|
}
|
|
193
196
|
type ServerRouteHandler = (ctx: ServerRouteContext, next?: () => Promise<void>) => void | Promise<void>;
|
|
194
197
|
type Middleware = (ctx: ServerRouteContext, next: () => Promise<void>) => void | Promise<void>;
|
|
195
198
|
declare class ServerRouter {
|
|
196
199
|
private routes;
|
|
197
200
|
private middlewares;
|
|
198
|
-
use(
|
|
199
|
-
|
|
201
|
+
use(...args: Array<any>): this;
|
|
202
|
+
all: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
200
203
|
get: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
201
204
|
post: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
202
205
|
put: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
203
206
|
delete: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
204
207
|
patch: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
205
208
|
options: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
209
|
+
head: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
210
|
+
private toMiddleware;
|
|
206
211
|
private addRoute;
|
|
207
212
|
private pathToRegex;
|
|
208
213
|
private parseQuery;
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './http.mjs';
|
|
2
2
|
import './ws.mjs';
|
|
3
|
-
export { H as HttpMethod, M as Middleware, S as ServerRouteContext, b as ServerRouteHandler, c as ServerRouter, q as SharedState, p as SharedStateOptions, o as StateChangeHandler, u as StateManager, g as bodyLimit, i as cacheControl, d as clearImportMapCache, k as compress, e as cors, v as createDevServer, n as createProxyHandler, f as errorHandler, h as html, j as json, l as logger, r as rateLimit, m as security, s as status, t as text } from './server-
|
|
3
|
+
export { H as HttpMethod, M as Middleware, S as ServerRouteContext, b as ServerRouteHandler, c as ServerRouter, q as SharedState, p as SharedStateOptions, o as StateChangeHandler, u as StateManager, g as bodyLimit, i as cacheControl, d as clearImportMapCache, k as compress, e as cors, v as createDevServer, n as createProxyHandler, f as errorHandler, h as html, j as json, l as logger, r as rateLimit, m as security, s as status, t as text } from './server-jAa9yJM4.mjs';
|
|
4
4
|
import 'node:events';
|
|
5
5
|
import 'events';
|
|
6
6
|
import 'http';
|
package/dist/server.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { IncomingMessage, ServerResponse } from './http';
|
|
9
9
|
import { WebSocket } from './ws';
|
|
10
10
|
import type { DevServerOptions, DevServer, ProxyConfig } from './types';
|
|
11
|
-
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
11
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
|
|
12
12
|
export interface ServerRouteContext {
|
|
13
13
|
req: IncomingMessage;
|
|
14
14
|
res: ServerResponse;
|
|
@@ -17,20 +17,25 @@ export interface ServerRouteContext {
|
|
|
17
17
|
body: any;
|
|
18
18
|
headers: Record<string, string | string[] | undefined>;
|
|
19
19
|
user?: any;
|
|
20
|
+
send?(data: any): ServerResponse;
|
|
21
|
+
json?(data: any): ServerResponse;
|
|
22
|
+
status?(code: number): ServerResponse;
|
|
20
23
|
}
|
|
21
24
|
export type ServerRouteHandler = (ctx: ServerRouteContext, next?: () => Promise<void>) => void | Promise<void>;
|
|
22
25
|
export type Middleware = (ctx: ServerRouteContext, next: () => Promise<void>) => void | Promise<void>;
|
|
23
26
|
export declare class ServerRouter {
|
|
24
27
|
private routes;
|
|
25
28
|
private middlewares;
|
|
26
|
-
use(
|
|
27
|
-
|
|
29
|
+
use(...args: Array<any>): this;
|
|
30
|
+
all: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
28
31
|
get: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
29
32
|
post: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
30
33
|
put: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
31
34
|
delete: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
32
35
|
patch: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
33
36
|
options: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
37
|
+
head: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
38
|
+
private toMiddleware;
|
|
34
39
|
private addRoute;
|
|
35
40
|
private pathToRegex;
|
|
36
41
|
private parseQuery;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,eAAe,EAAE,cAAc,EAA0B,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAmB,SAAS,EAAc,MAAM,MAAM,CAAC;AAM9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAA4B,WAAW,EAAE,MAAM,SAAS,CAAC;AAKlG,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,eAAe,EAAE,cAAc,EAA0B,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAmB,SAAS,EAAc,MAAM,MAAM,CAAC;AAM9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAA4B,WAAW,EAAE,MAAM,SAAS,CAAC;AAKlG,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;AAElG,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,eAAe,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;I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 +2662,8 @@ var ServerRouter = class {
|
|
|
2662
2662
|
constructor() {
|
|
2663
2663
|
this.routes = [];
|
|
2664
2664
|
this.middlewares = [];
|
|
2665
|
+
// Express-like .all() method - matches all HTTP methods
|
|
2666
|
+
this.all = (path, ...handlers) => this.addRoute("ALL", path, handlers);
|
|
2665
2667
|
// Support per-route middleware: accept middleware(s) before the final handler
|
|
2666
2668
|
this.get = (path, ...handlers) => this.addRoute("GET", path, handlers);
|
|
2667
2669
|
this.post = (path, ...handlers) => this.addRoute("POST", path, handlers);
|
|
@@ -2669,9 +2671,17 @@ var ServerRouter = class {
|
|
|
2669
2671
|
this.delete = (path, ...handlers) => this.addRoute("DELETE", path, handlers);
|
|
2670
2672
|
this.patch = (path, ...handlers) => this.addRoute("PATCH", path, handlers);
|
|
2671
2673
|
this.options = (path, ...handlers) => this.addRoute("OPTIONS", path, handlers);
|
|
2674
|
+
this.head = (path, ...handlers) => this.addRoute("HEAD", path, handlers);
|
|
2672
2675
|
}
|
|
2673
2676
|
// Accept both internal Middleware and Express-style `(req, res, next?)` functions
|
|
2674
|
-
use(
|
|
2677
|
+
// Also support path-based middleware like Express: use(path, middleware)
|
|
2678
|
+
use(...args) {
|
|
2679
|
+
if (typeof args[0] === "string") {
|
|
2680
|
+
const path = args[0];
|
|
2681
|
+
const middlewares = args.slice(1);
|
|
2682
|
+
return this.addRoute("ALL", path, middlewares);
|
|
2683
|
+
}
|
|
2684
|
+
const mw = args[0];
|
|
2675
2685
|
this.middlewares.push(this.toMiddleware(mw));
|
|
2676
2686
|
return this;
|
|
2677
2687
|
}
|
|
@@ -2792,7 +2802,8 @@ var ServerRouter = class {
|
|
|
2792
2802
|
async handle(req, res) {
|
|
2793
2803
|
const method = req.method, url = req.url || "/", path = url.split("?")[0];
|
|
2794
2804
|
for (const route of this.routes) {
|
|
2795
|
-
if (route.method !==
|
|
2805
|
+
if (route.method !== "ALL" && route.method !== method) continue;
|
|
2806
|
+
if (!route.pattern.test(path)) continue;
|
|
2796
2807
|
const match = path.match(route.pattern);
|
|
2797
2808
|
const params = Object.fromEntries(route.paramNames.map((name, i2) => [name, match[i2 + 1]]));
|
|
2798
2809
|
let body = {};
|
|
@@ -2805,7 +2816,38 @@ var ServerRouter = class {
|
|
|
2805
2816
|
return true;
|
|
2806
2817
|
}
|
|
2807
2818
|
}
|
|
2808
|
-
const ctx = {
|
|
2819
|
+
const ctx = {
|
|
2820
|
+
req,
|
|
2821
|
+
res,
|
|
2822
|
+
params,
|
|
2823
|
+
query: this.parseQuery(url),
|
|
2824
|
+
body,
|
|
2825
|
+
headers: req.headers,
|
|
2826
|
+
send: (data) => {
|
|
2827
|
+
if (!res.headersSent) {
|
|
2828
|
+
if (typeof data === "object") {
|
|
2829
|
+
res.setHeader("Content-Type", "application/json");
|
|
2830
|
+
res.end(JSON.stringify(data));
|
|
2831
|
+
} else {
|
|
2832
|
+
res.end(String(data));
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
return res;
|
|
2836
|
+
},
|
|
2837
|
+
json: (data) => {
|
|
2838
|
+
if (!res.headersSent) {
|
|
2839
|
+
res.setHeader("Content-Type", "application/json");
|
|
2840
|
+
res.end(JSON.stringify(data));
|
|
2841
|
+
}
|
|
2842
|
+
return res;
|
|
2843
|
+
},
|
|
2844
|
+
status: (code) => {
|
|
2845
|
+
if (!res.headersSent) {
|
|
2846
|
+
res.statusCode = code;
|
|
2847
|
+
}
|
|
2848
|
+
return res;
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2809
2851
|
const routeMiddlewares = route.middlewares || [];
|
|
2810
2852
|
const chain = [
|
|
2811
2853
|
...this.middlewares,
|
package/dist/server.mjs
CHANGED
|
@@ -2636,6 +2636,8 @@ var ServerRouter = class {
|
|
|
2636
2636
|
constructor() {
|
|
2637
2637
|
this.routes = [];
|
|
2638
2638
|
this.middlewares = [];
|
|
2639
|
+
// Express-like .all() method - matches all HTTP methods
|
|
2640
|
+
this.all = (path, ...handlers) => this.addRoute("ALL", path, handlers);
|
|
2639
2641
|
// Support per-route middleware: accept middleware(s) before the final handler
|
|
2640
2642
|
this.get = (path, ...handlers) => this.addRoute("GET", path, handlers);
|
|
2641
2643
|
this.post = (path, ...handlers) => this.addRoute("POST", path, handlers);
|
|
@@ -2643,9 +2645,17 @@ var ServerRouter = class {
|
|
|
2643
2645
|
this.delete = (path, ...handlers) => this.addRoute("DELETE", path, handlers);
|
|
2644
2646
|
this.patch = (path, ...handlers) => this.addRoute("PATCH", path, handlers);
|
|
2645
2647
|
this.options = (path, ...handlers) => this.addRoute("OPTIONS", path, handlers);
|
|
2648
|
+
this.head = (path, ...handlers) => this.addRoute("HEAD", path, handlers);
|
|
2646
2649
|
}
|
|
2647
2650
|
// Accept both internal Middleware and Express-style `(req, res, next?)` functions
|
|
2648
|
-
use(
|
|
2651
|
+
// Also support path-based middleware like Express: use(path, middleware)
|
|
2652
|
+
use(...args) {
|
|
2653
|
+
if (typeof args[0] === "string") {
|
|
2654
|
+
const path = args[0];
|
|
2655
|
+
const middlewares = args.slice(1);
|
|
2656
|
+
return this.addRoute("ALL", path, middlewares);
|
|
2657
|
+
}
|
|
2658
|
+
const mw = args[0];
|
|
2649
2659
|
this.middlewares.push(this.toMiddleware(mw));
|
|
2650
2660
|
return this;
|
|
2651
2661
|
}
|
|
@@ -2766,7 +2776,8 @@ var ServerRouter = class {
|
|
|
2766
2776
|
async handle(req, res) {
|
|
2767
2777
|
const method = req.method, url = req.url || "/", path = url.split("?")[0];
|
|
2768
2778
|
for (const route of this.routes) {
|
|
2769
|
-
if (route.method !==
|
|
2779
|
+
if (route.method !== "ALL" && route.method !== method) continue;
|
|
2780
|
+
if (!route.pattern.test(path)) continue;
|
|
2770
2781
|
const match = path.match(route.pattern);
|
|
2771
2782
|
const params = Object.fromEntries(route.paramNames.map((name, i2) => [name, match[i2 + 1]]));
|
|
2772
2783
|
let body = {};
|
|
@@ -2779,7 +2790,38 @@ var ServerRouter = class {
|
|
|
2779
2790
|
return true;
|
|
2780
2791
|
}
|
|
2781
2792
|
}
|
|
2782
|
-
const ctx = {
|
|
2793
|
+
const ctx = {
|
|
2794
|
+
req,
|
|
2795
|
+
res,
|
|
2796
|
+
params,
|
|
2797
|
+
query: this.parseQuery(url),
|
|
2798
|
+
body,
|
|
2799
|
+
headers: req.headers,
|
|
2800
|
+
send: (data) => {
|
|
2801
|
+
if (!res.headersSent) {
|
|
2802
|
+
if (typeof data === "object") {
|
|
2803
|
+
res.setHeader("Content-Type", "application/json");
|
|
2804
|
+
res.end(JSON.stringify(data));
|
|
2805
|
+
} else {
|
|
2806
|
+
res.end(String(data));
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
return res;
|
|
2810
|
+
},
|
|
2811
|
+
json: (data) => {
|
|
2812
|
+
if (!res.headersSent) {
|
|
2813
|
+
res.setHeader("Content-Type", "application/json");
|
|
2814
|
+
res.end(JSON.stringify(data));
|
|
2815
|
+
}
|
|
2816
|
+
return res;
|
|
2817
|
+
},
|
|
2818
|
+
status: (code) => {
|
|
2819
|
+
if (!res.headersSent) {
|
|
2820
|
+
res.statusCode = code;
|
|
2821
|
+
}
|
|
2822
|
+
return res;
|
|
2823
|
+
}
|
|
2824
|
+
};
|
|
2783
2825
|
const routeMiddlewares = route.middlewares || [];
|
|
2784
2826
|
const chain = [
|
|
2785
2827
|
...this.middlewares,
|
package/dist/types.d.mts
CHANGED
|
@@ -156,20 +156,25 @@ interface ServerRouteContext {
|
|
|
156
156
|
body: any;
|
|
157
157
|
headers: Record<string, string | string[] | undefined>;
|
|
158
158
|
user?: any;
|
|
159
|
+
send?(data: any): ServerResponse;
|
|
160
|
+
json?(data: any): ServerResponse;
|
|
161
|
+
status?(code: number): ServerResponse;
|
|
159
162
|
}
|
|
160
163
|
type ServerRouteHandler = (ctx: ServerRouteContext, next?: () => Promise<void>) => void | Promise<void>;
|
|
161
164
|
type Middleware = (ctx: ServerRouteContext, next: () => Promise<void>) => void | Promise<void>;
|
|
162
165
|
declare class ServerRouter {
|
|
163
166
|
private routes;
|
|
164
167
|
private middlewares;
|
|
165
|
-
use(
|
|
166
|
-
|
|
168
|
+
use(...args: Array<any>): this;
|
|
169
|
+
all: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
167
170
|
get: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
168
171
|
post: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
169
172
|
put: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
170
173
|
delete: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
171
174
|
patch: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
172
175
|
options: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
176
|
+
head: (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>) => this;
|
|
177
|
+
private toMiddleware;
|
|
173
178
|
private addRoute;
|
|
174
179
|
private pathToRegex;
|
|
175
180
|
private parseQuery;
|
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { dom } from './dom';
|
|
|
19
19
|
|
|
20
20
|
// ===== Router =====
|
|
21
21
|
|
|
22
|
-
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
22
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
|
|
23
23
|
|
|
24
24
|
export interface ServerRouteContext {
|
|
25
25
|
req: IncomingMessage;
|
|
@@ -29,6 +29,10 @@ export interface ServerRouteContext {
|
|
|
29
29
|
body: any;
|
|
30
30
|
headers: Record<string, string | string[] | undefined>;
|
|
31
31
|
user?: any;
|
|
32
|
+
// Express-compatible response helpers
|
|
33
|
+
send?(data: any): ServerResponse;
|
|
34
|
+
json?(data: any): ServerResponse;
|
|
35
|
+
status?(code: number): ServerResponse;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export type ServerRouteHandler = (ctx: ServerRouteContext, next?: () => Promise<void>) => void | Promise<void>;
|
|
@@ -47,11 +51,32 @@ export class ServerRouter {
|
|
|
47
51
|
private middlewares: Middleware[] = [];
|
|
48
52
|
|
|
49
53
|
// Accept both internal Middleware and Express-style `(req, res, next?)` functions
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
// Also support path-based middleware like Express: use(path, middleware)
|
|
55
|
+
use(...args: Array<any>): this {
|
|
56
|
+
if (typeof args[0] === 'string') {
|
|
57
|
+
// Path-based middleware: use(path, ...middlewares)
|
|
58
|
+
const path = args[0];
|
|
59
|
+
const middlewares = args.slice(1);
|
|
60
|
+
return this.addRoute('ALL', path, middlewares);
|
|
61
|
+
}
|
|
62
|
+
// Global middleware
|
|
63
|
+
const mw = args[0];
|
|
64
|
+
this.middlewares.push(this.toMiddleware(mw));
|
|
52
65
|
return this;
|
|
53
66
|
}
|
|
54
67
|
|
|
68
|
+
// Express-like .all() method - matches all HTTP methods
|
|
69
|
+
all = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('ALL', path, handlers as any);
|
|
70
|
+
|
|
71
|
+
// Support per-route middleware: accept middleware(s) before the final handler
|
|
72
|
+
get = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('GET', path, handlers as any);
|
|
73
|
+
post = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('POST', path, handlers as any);
|
|
74
|
+
put = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('PUT', path, handlers as any);
|
|
75
|
+
delete = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('DELETE', path, handlers as any);
|
|
76
|
+
patch = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('PATCH', path, handlers as any);
|
|
77
|
+
options = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('OPTIONS', path, handlers as any);
|
|
78
|
+
head = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('HEAD', path, handlers as any);
|
|
79
|
+
|
|
55
80
|
// Convert Express-like handler/middleware to internal Middleware
|
|
56
81
|
private toMiddleware(fn: Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)): Middleware {
|
|
57
82
|
// If it's already our Middleware, return as-is
|
|
@@ -91,14 +116,6 @@ export class ServerRouter {
|
|
|
91
116
|
};
|
|
92
117
|
}
|
|
93
118
|
|
|
94
|
-
// Support per-route middleware: accept middleware(s) before the final handler
|
|
95
|
-
get = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('GET', path, handlers as any);
|
|
96
|
-
post = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('POST', path, handlers as any);
|
|
97
|
-
put = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('PUT', path, handlers as any);
|
|
98
|
-
delete = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('DELETE', path, handlers as any);
|
|
99
|
-
patch = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('PATCH', path, handlers as any);
|
|
100
|
-
options = (path: string, ...handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this => this.addRoute('OPTIONS', path, handlers as any);
|
|
101
|
-
|
|
102
119
|
private addRoute(method: HttpMethod, path: string, handlers: Array<Middleware | ServerRouteHandler | ((req: IncomingMessage, res: ServerResponse, next?: () => void) => any)>): this {
|
|
103
120
|
const { pattern, paramNames } = this.pathToRegex(path);
|
|
104
121
|
// Last item is the actual route handler, preceding items are middlewares
|
|
@@ -216,7 +233,8 @@ export class ServerRouter {
|
|
|
216
233
|
const method = req.method as HttpMethod, url = req.url || '/', path = url.split('?')[0];
|
|
217
234
|
|
|
218
235
|
for (const route of this.routes) {
|
|
219
|
-
if (route.method !==
|
|
236
|
+
if (route.method !== 'ALL' && route.method !== method) continue;
|
|
237
|
+
if (!route.pattern.test(path)) continue;
|
|
220
238
|
const match = path.match(route.pattern)!;
|
|
221
239
|
const params = Object.fromEntries(route.paramNames.map((name, i) => [name, match[i + 1]]));
|
|
222
240
|
|
|
@@ -232,7 +250,39 @@ export class ServerRouter {
|
|
|
232
250
|
}
|
|
233
251
|
}
|
|
234
252
|
|
|
235
|
-
|
|
253
|
+
// Add Express-like response helpers to context
|
|
254
|
+
const ctx: ServerRouteContext = {
|
|
255
|
+
req,
|
|
256
|
+
res,
|
|
257
|
+
params,
|
|
258
|
+
query: this.parseQuery(url),
|
|
259
|
+
body,
|
|
260
|
+
headers: req.headers as any,
|
|
261
|
+
send: (data: any) => {
|
|
262
|
+
if (!res.headersSent) {
|
|
263
|
+
if (typeof data === 'object') {
|
|
264
|
+
res.setHeader('Content-Type', 'application/json');
|
|
265
|
+
res.end(JSON.stringify(data));
|
|
266
|
+
} else {
|
|
267
|
+
res.end(String(data));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return res;
|
|
271
|
+
},
|
|
272
|
+
json: (data: any) => {
|
|
273
|
+
if (!res.headersSent) {
|
|
274
|
+
res.setHeader('Content-Type', 'application/json');
|
|
275
|
+
res.end(JSON.stringify(data));
|
|
276
|
+
}
|
|
277
|
+
return res;
|
|
278
|
+
},
|
|
279
|
+
status: (code: number) => {
|
|
280
|
+
if (!res.headersSent) {
|
|
281
|
+
res.statusCode = code;
|
|
282
|
+
}
|
|
283
|
+
return res;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
236
286
|
|
|
237
287
|
// Build middleware chain: global middlewares -> route middlewares -> final handler
|
|
238
288
|
// Pass `next` to the final handler so it can optionally call await next()
|