@wooksjs/event-http 0.7.28 → 0.7.30
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/index.cjs +25 -14
- package/dist/index.d.ts +10 -3
- package/dist/index.mjs +25 -14
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1881,7 +1881,7 @@ function escapeHtml(value) {
|
|
|
1881
1881
|
//#endregion
|
|
1882
1882
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1883
1883
|
let framework = {
|
|
1884
|
-
version: "0.7.
|
|
1884
|
+
version: "0.7.30",
|
|
1885
1885
|
poweredBy: "wooksjs",
|
|
1886
1886
|
link: "https://wooks.moost.org/",
|
|
1887
1887
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
@@ -2094,6 +2094,12 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
2094
2094
|
* const server = http.createServer(app.getServerCb())
|
|
2095
2095
|
* server.listen(3000)
|
|
2096
2096
|
* ```
|
|
2097
|
+
*
|
|
2098
|
+
* Pass `onNoMatch` to mount Wooks as a middleware in front of another handler
|
|
2099
|
+
* (e.g. a Vite dev server). The request is routed first; when no route matches,
|
|
2100
|
+
* `onNoMatch(req, res)` is called directly — before and outside any event context:
|
|
2101
|
+
* no response wrapper is created, no event starts (`current()` throws, no
|
|
2102
|
+
* `ContextInjector` hooks fire) and `onNotFound` is skipped.
|
|
2097
2103
|
*/
|
|
2098
2104
|
getServerCb(onNoMatch) {
|
|
2099
2105
|
const ctxOptions = this.eventContextOptions;
|
|
@@ -2102,18 +2108,22 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
2102
2108
|
const defaultHeaders = this.opts?.defaultHeaders;
|
|
2103
2109
|
const compression = this.compression;
|
|
2104
2110
|
return (req, res) => {
|
|
2105
|
-
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders, false, compression);
|
|
2106
2111
|
const method = req.method || "";
|
|
2107
2112
|
const url = req.url || "";
|
|
2113
|
+
const match = this.wooks.matchRoute(method, url);
|
|
2114
|
+
if (!match && onNoMatch) {
|
|
2115
|
+
onNoMatch(req, res);
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders, false, compression);
|
|
2108
2119
|
createHttpContext(ctxOptions, {
|
|
2109
2120
|
req,
|
|
2110
2121
|
response,
|
|
2111
2122
|
requestLimits: RequestLimits
|
|
2112
2123
|
}, () => {
|
|
2113
2124
|
const ctx = (0, _wooksjs_event_core.current)();
|
|
2114
|
-
const handlers = this.wooks.
|
|
2125
|
+
const handlers = this.wooks.applyRoute(method, match, ctx);
|
|
2115
2126
|
if (handlers) return this.processAndCatch(handlers, ctx, response);
|
|
2116
|
-
else if (onNoMatch) onNoMatch(req, res);
|
|
2117
2127
|
else if (notFoundHandler) return this.processAndCatch([notFoundHandler], ctx, response);
|
|
2118
2128
|
else {
|
|
2119
2129
|
this.logger.debug(`404 Not found (${method})${url}`);
|
|
@@ -2220,20 +2230,23 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
2220
2230
|
}
|
|
2221
2231
|
/**
|
|
2222
2232
|
* Programmatic route invocation using the Web Standard fetch API.
|
|
2223
|
-
* Goes through the full dispatch pipeline:
|
|
2224
|
-
* handler execution, response finalization.
|
|
2233
|
+
* Goes through the full dispatch pipeline: route matching, context creation,
|
|
2234
|
+
* handler execution, response finalization. An unmatched route returns `null`
|
|
2235
|
+
* before any event context is created (the request body is left unread).
|
|
2225
2236
|
*
|
|
2226
2237
|
* When called from within an existing HTTP context (e.g. during SSR),
|
|
2227
2238
|
* identity headers (authorization, cookie) are automatically forwarded
|
|
2228
2239
|
* from the calling request unless already present on the given Request.
|
|
2229
2240
|
*
|
|
2230
2241
|
* @param request - A Web Standard Request object.
|
|
2231
|
-
* @returns A Web Standard Response, or `null` if no route matched (
|
|
2242
|
+
* @returns A Web Standard Response, or `null` if no route matched (`onNotFound` is not used here).
|
|
2232
2243
|
*/
|
|
2233
2244
|
async fetch(request) {
|
|
2234
2245
|
const url = new URL(request.url);
|
|
2235
2246
|
const method = request.method;
|
|
2236
2247
|
const pathname = url.pathname + url.search;
|
|
2248
|
+
const match = this.wooks.matchRoute(method, pathname);
|
|
2249
|
+
if (!match) return null;
|
|
2237
2250
|
const callerCtx = (0, _wooksjs_event_core.tryGetCurrent)();
|
|
2238
2251
|
let callerReq;
|
|
2239
2252
|
if (callerCtx) try {
|
|
@@ -2282,13 +2295,11 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
2282
2295
|
const ctx = (0, _wooksjs_event_core.current)();
|
|
2283
2296
|
if (bodyBuffer) seedRawBody(ctx, bodyBuffer);
|
|
2284
2297
|
try {
|
|
2285
|
-
const handlers = this.wooks.
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
if (
|
|
2289
|
-
|
|
2290
|
-
});
|
|
2291
|
-
} else return null;
|
|
2298
|
+
const handlers = this.wooks.applyRoute(method, match, ctx);
|
|
2299
|
+
const result = this.processHandlers(handlers, ctx, response);
|
|
2300
|
+
if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
|
|
2301
|
+
if (!response.responded) this.respond(error, response, ctx);
|
|
2302
|
+
});
|
|
2292
2303
|
} finally {
|
|
2293
2304
|
fakeReq.emit("end");
|
|
2294
2305
|
fakeReq.emit("close");
|
package/dist/index.d.ts
CHANGED
|
@@ -778,6 +778,12 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
778
778
|
* const server = http.createServer(app.getServerCb())
|
|
779
779
|
* server.listen(3000)
|
|
780
780
|
* ```
|
|
781
|
+
*
|
|
782
|
+
* Pass `onNoMatch` to mount Wooks as a middleware in front of another handler
|
|
783
|
+
* (e.g. a Vite dev server). The request is routed first; when no route matches,
|
|
784
|
+
* `onNoMatch(req, res)` is called directly — before and outside any event context:
|
|
785
|
+
* no response wrapper is created, no event starts (`current()` throws, no
|
|
786
|
+
* `ContextInjector` hooks fire) and `onNotFound` is skipped.
|
|
781
787
|
*/
|
|
782
788
|
getServerCb(onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void): (req: IncomingMessage, res: ServerResponse) => void;
|
|
783
789
|
/**
|
|
@@ -792,15 +798,16 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
792
798
|
private processAsyncResult;
|
|
793
799
|
/**
|
|
794
800
|
* Programmatic route invocation using the Web Standard fetch API.
|
|
795
|
-
* Goes through the full dispatch pipeline:
|
|
796
|
-
* handler execution, response finalization.
|
|
801
|
+
* Goes through the full dispatch pipeline: route matching, context creation,
|
|
802
|
+
* handler execution, response finalization. An unmatched route returns `null`
|
|
803
|
+
* before any event context is created (the request body is left unread).
|
|
797
804
|
*
|
|
798
805
|
* When called from within an existing HTTP context (e.g. during SSR),
|
|
799
806
|
* identity headers (authorization, cookie) are automatically forwarded
|
|
800
807
|
* from the calling request unless already present on the given Request.
|
|
801
808
|
*
|
|
802
809
|
* @param request - A Web Standard Request object.
|
|
803
|
-
* @returns A Web Standard Response, or `null` if no route matched (
|
|
810
|
+
* @returns A Web Standard Response, or `null` if no route matched (`onNotFound` is not used here).
|
|
804
811
|
*/
|
|
805
812
|
fetch(request: Request): Promise<Response | null>;
|
|
806
813
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1852,7 +1852,7 @@ function escapeHtml(value) {
|
|
|
1852
1852
|
//#endregion
|
|
1853
1853
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1854
1854
|
let framework = {
|
|
1855
|
-
version: "0.7.
|
|
1855
|
+
version: "0.7.30",
|
|
1856
1856
|
poweredBy: "wooksjs",
|
|
1857
1857
|
link: "https://wooks.moost.org/",
|
|
1858
1858
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
@@ -2065,6 +2065,12 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
2065
2065
|
* const server = http.createServer(app.getServerCb())
|
|
2066
2066
|
* server.listen(3000)
|
|
2067
2067
|
* ```
|
|
2068
|
+
*
|
|
2069
|
+
* Pass `onNoMatch` to mount Wooks as a middleware in front of another handler
|
|
2070
|
+
* (e.g. a Vite dev server). The request is routed first; when no route matches,
|
|
2071
|
+
* `onNoMatch(req, res)` is called directly — before and outside any event context:
|
|
2072
|
+
* no response wrapper is created, no event starts (`current()` throws, no
|
|
2073
|
+
* `ContextInjector` hooks fire) and `onNotFound` is skipped.
|
|
2068
2074
|
*/
|
|
2069
2075
|
getServerCb(onNoMatch) {
|
|
2070
2076
|
const ctxOptions = this.eventContextOptions;
|
|
@@ -2073,18 +2079,22 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
2073
2079
|
const defaultHeaders = this.opts?.defaultHeaders;
|
|
2074
2080
|
const compression = this.compression;
|
|
2075
2081
|
return (req, res) => {
|
|
2076
|
-
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders, false, compression);
|
|
2077
2082
|
const method = req.method || "";
|
|
2078
2083
|
const url = req.url || "";
|
|
2084
|
+
const match = this.wooks.matchRoute(method, url);
|
|
2085
|
+
if (!match && onNoMatch) {
|
|
2086
|
+
onNoMatch(req, res);
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders, false, compression);
|
|
2079
2090
|
createHttpContext(ctxOptions, {
|
|
2080
2091
|
req,
|
|
2081
2092
|
response,
|
|
2082
2093
|
requestLimits: RequestLimits
|
|
2083
2094
|
}, () => {
|
|
2084
2095
|
const ctx = current();
|
|
2085
|
-
const handlers = this.wooks.
|
|
2096
|
+
const handlers = this.wooks.applyRoute(method, match, ctx);
|
|
2086
2097
|
if (handlers) return this.processAndCatch(handlers, ctx, response);
|
|
2087
|
-
else if (onNoMatch) onNoMatch(req, res);
|
|
2088
2098
|
else if (notFoundHandler) return this.processAndCatch([notFoundHandler], ctx, response);
|
|
2089
2099
|
else {
|
|
2090
2100
|
this.logger.debug(`404 Not found (${method})${url}`);
|
|
@@ -2191,20 +2201,23 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
2191
2201
|
}
|
|
2192
2202
|
/**
|
|
2193
2203
|
* Programmatic route invocation using the Web Standard fetch API.
|
|
2194
|
-
* Goes through the full dispatch pipeline:
|
|
2195
|
-
* handler execution, response finalization.
|
|
2204
|
+
* Goes through the full dispatch pipeline: route matching, context creation,
|
|
2205
|
+
* handler execution, response finalization. An unmatched route returns `null`
|
|
2206
|
+
* before any event context is created (the request body is left unread).
|
|
2196
2207
|
*
|
|
2197
2208
|
* When called from within an existing HTTP context (e.g. during SSR),
|
|
2198
2209
|
* identity headers (authorization, cookie) are automatically forwarded
|
|
2199
2210
|
* from the calling request unless already present on the given Request.
|
|
2200
2211
|
*
|
|
2201
2212
|
* @param request - A Web Standard Request object.
|
|
2202
|
-
* @returns A Web Standard Response, or `null` if no route matched (
|
|
2213
|
+
* @returns A Web Standard Response, or `null` if no route matched (`onNotFound` is not used here).
|
|
2203
2214
|
*/
|
|
2204
2215
|
async fetch(request) {
|
|
2205
2216
|
const url = new URL(request.url);
|
|
2206
2217
|
const method = request.method;
|
|
2207
2218
|
const pathname = url.pathname + url.search;
|
|
2219
|
+
const match = this.wooks.matchRoute(method, pathname);
|
|
2220
|
+
if (!match) return null;
|
|
2208
2221
|
const callerCtx = tryGetCurrent();
|
|
2209
2222
|
let callerReq;
|
|
2210
2223
|
if (callerCtx) try {
|
|
@@ -2253,13 +2266,11 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
2253
2266
|
const ctx = current();
|
|
2254
2267
|
if (bodyBuffer) seedRawBody(ctx, bodyBuffer);
|
|
2255
2268
|
try {
|
|
2256
|
-
const handlers = this.wooks.
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
if (
|
|
2260
|
-
|
|
2261
|
-
});
|
|
2262
|
-
} else return null;
|
|
2269
|
+
const handlers = this.wooks.applyRoute(method, match, ctx);
|
|
2270
|
+
const result = this.processHandlers(handlers, ctx, response);
|
|
2271
|
+
if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
|
|
2272
|
+
if (!response.responded) this.respond(error, response, ctx);
|
|
2273
|
+
});
|
|
2263
2274
|
} finally {
|
|
2264
2275
|
fakeReq.emit("end");
|
|
2265
2276
|
fakeReq.emit("close");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.30",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^3.2.7",
|
|
45
|
-
"@wooksjs/event-core": "^0.7.
|
|
46
|
-
"wooks": "^0.7.
|
|
45
|
+
"@wooksjs/event-core": "^0.7.30",
|
|
46
|
+
"wooks": "^0.7.30"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@prostojs/logger": "^0.4.3",
|
|
50
|
-
"@prostojs/router": "^0.3.
|
|
51
|
-
"@wooksjs/event-core": "^0.7.
|
|
52
|
-
"wooks": "^0.7.
|
|
50
|
+
"@prostojs/router": "^0.3.6",
|
|
51
|
+
"@wooksjs/event-core": "^0.7.30",
|
|
52
|
+
"wooks": "^0.7.30"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "rolldown -c ../../rolldown.config.mjs"
|