@hono/node-server 1.3.4 → 1.4.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.
- package/README.md +16 -0
- package/dist/index.js +4 -11
- package/dist/index.mjs +4 -11
- package/dist/listener.js +4 -11
- package/dist/listener.mjs +4 -11
- package/dist/serve-static.d.mts +2 -1
- package/dist/serve-static.d.ts +2 -1
- package/dist/serve-static.js +1 -0
- package/dist/serve-static.mjs +1 -0
- package/dist/server.js +4 -11
- package/dist/server.mjs +4 -11
- package/dist/vercel.js +4 -11
- package/dist/vercel.mjs +4 -11
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -162,6 +162,22 @@ app.use(
|
|
|
162
162
|
)
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
+
#### `onNotFound`
|
|
166
|
+
|
|
167
|
+
The `onNotFound` is useful for debugging. You can write a handle for when a file is not found.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
app.use(
|
|
171
|
+
'/static/*',
|
|
172
|
+
serveStatic({
|
|
173
|
+
root: './non-existent-dir',
|
|
174
|
+
onNotFound: (path, c) => {
|
|
175
|
+
console.log(`${path} is not found, request to ${c.req.path}`)
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
165
181
|
## Related projects
|
|
166
182
|
|
|
167
183
|
- Hono - <https://hono.dev>
|
package/dist/index.js
CHANGED
|
@@ -281,19 +281,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
281
281
|
if (res instanceof Promise) {
|
|
282
282
|
res = await res.catch(handleFetchError);
|
|
283
283
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// @ts-expect-error the object must have `toString()`
|
|
287
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
288
|
-
outgoing
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
if (cacheKey in res) {
|
|
292
|
-
try {
|
|
284
|
+
try {
|
|
285
|
+
if (cacheKey in res) {
|
|
293
286
|
return responseViaCache(res, outgoing);
|
|
294
|
-
} catch (e) {
|
|
295
|
-
return handleResponseError(e, outgoing);
|
|
296
287
|
}
|
|
288
|
+
} catch (e) {
|
|
289
|
+
return handleResponseError(e, outgoing);
|
|
297
290
|
}
|
|
298
291
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
299
292
|
if (res.body) {
|
package/dist/index.mjs
CHANGED
|
@@ -243,19 +243,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
243
243
|
if (res instanceof Promise) {
|
|
244
244
|
res = await res.catch(handleFetchError);
|
|
245
245
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// @ts-expect-error the object must have `toString()`
|
|
249
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
250
|
-
outgoing
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (cacheKey in res) {
|
|
254
|
-
try {
|
|
246
|
+
try {
|
|
247
|
+
if (cacheKey in res) {
|
|
255
248
|
return responseViaCache(res, outgoing);
|
|
256
|
-
} catch (e) {
|
|
257
|
-
return handleResponseError(e, outgoing);
|
|
258
249
|
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
return handleResponseError(e, outgoing);
|
|
259
252
|
}
|
|
260
253
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
261
254
|
if (res.body) {
|
package/dist/listener.js
CHANGED
|
@@ -276,19 +276,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
276
276
|
if (res instanceof Promise) {
|
|
277
277
|
res = await res.catch(handleFetchError);
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
// @ts-expect-error the object must have `toString()`
|
|
282
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
283
|
-
outgoing
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
if (cacheKey in res) {
|
|
287
|
-
try {
|
|
279
|
+
try {
|
|
280
|
+
if (cacheKey in res) {
|
|
288
281
|
return responseViaCache(res, outgoing);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
return handleResponseError(e, outgoing);
|
|
291
282
|
}
|
|
283
|
+
} catch (e) {
|
|
284
|
+
return handleResponseError(e, outgoing);
|
|
292
285
|
}
|
|
293
286
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
294
287
|
if (res.body) {
|
package/dist/listener.mjs
CHANGED
|
@@ -240,19 +240,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
240
240
|
if (res instanceof Promise) {
|
|
241
241
|
res = await res.catch(handleFetchError);
|
|
242
242
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// @ts-expect-error the object must have `toString()`
|
|
246
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
247
|
-
outgoing
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
if (cacheKey in res) {
|
|
251
|
-
try {
|
|
243
|
+
try {
|
|
244
|
+
if (cacheKey in res) {
|
|
252
245
|
return responseViaCache(res, outgoing);
|
|
253
|
-
} catch (e) {
|
|
254
|
-
return handleResponseError(e, outgoing);
|
|
255
246
|
}
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return handleResponseError(e, outgoing);
|
|
256
249
|
}
|
|
257
250
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
258
251
|
if (res.body) {
|
package/dist/serve-static.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MiddlewareHandler } from 'hono';
|
|
1
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
2
2
|
|
|
3
3
|
type ServeStaticOptions = {
|
|
4
4
|
/**
|
|
@@ -8,6 +8,7 @@ type ServeStaticOptions = {
|
|
|
8
8
|
path?: string;
|
|
9
9
|
index?: string;
|
|
10
10
|
rewriteRequestPath?: (path: string) => string;
|
|
11
|
+
onNotFound?: (path: string, c: Context) => void | Promise<void>;
|
|
11
12
|
};
|
|
12
13
|
declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
|
|
13
14
|
|
package/dist/serve-static.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MiddlewareHandler } from 'hono';
|
|
1
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
2
2
|
|
|
3
3
|
type ServeStaticOptions = {
|
|
4
4
|
/**
|
|
@@ -8,6 +8,7 @@ type ServeStaticOptions = {
|
|
|
8
8
|
path?: string;
|
|
9
9
|
index?: string;
|
|
10
10
|
rewriteRequestPath?: (path: string) => string;
|
|
11
|
+
onNotFound?: (path: string, c: Context) => void | Promise<void>;
|
|
11
12
|
};
|
|
12
13
|
declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
|
|
13
14
|
|
package/dist/serve-static.js
CHANGED
package/dist/serve-static.mjs
CHANGED
package/dist/server.js
CHANGED
|
@@ -278,19 +278,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
278
278
|
if (res instanceof Promise) {
|
|
279
279
|
res = await res.catch(handleFetchError);
|
|
280
280
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
// @ts-expect-error the object must have `toString()`
|
|
284
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
285
|
-
outgoing
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
if (cacheKey in res) {
|
|
289
|
-
try {
|
|
281
|
+
try {
|
|
282
|
+
if (cacheKey in res) {
|
|
290
283
|
return responseViaCache(res, outgoing);
|
|
291
|
-
} catch (e) {
|
|
292
|
-
return handleResponseError(e, outgoing);
|
|
293
284
|
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return handleResponseError(e, outgoing);
|
|
294
287
|
}
|
|
295
288
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
296
289
|
if (res.body) {
|
package/dist/server.mjs
CHANGED
|
@@ -243,19 +243,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
243
243
|
if (res instanceof Promise) {
|
|
244
244
|
res = await res.catch(handleFetchError);
|
|
245
245
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// @ts-expect-error the object must have `toString()`
|
|
249
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
250
|
-
outgoing
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (cacheKey in res) {
|
|
254
|
-
try {
|
|
246
|
+
try {
|
|
247
|
+
if (cacheKey in res) {
|
|
255
248
|
return responseViaCache(res, outgoing);
|
|
256
|
-
} catch (e) {
|
|
257
|
-
return handleResponseError(e, outgoing);
|
|
258
249
|
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
return handleResponseError(e, outgoing);
|
|
259
252
|
}
|
|
260
253
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
261
254
|
if (res.body) {
|
package/dist/vercel.js
CHANGED
|
@@ -276,19 +276,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
276
276
|
if (res instanceof Promise) {
|
|
277
277
|
res = await res.catch(handleFetchError);
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
// @ts-expect-error the object must have `toString()`
|
|
282
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
283
|
-
outgoing
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
if (cacheKey in res) {
|
|
287
|
-
try {
|
|
279
|
+
try {
|
|
280
|
+
if (cacheKey in res) {
|
|
288
281
|
return responseViaCache(res, outgoing);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
return handleResponseError(e, outgoing);
|
|
291
282
|
}
|
|
283
|
+
} catch (e) {
|
|
284
|
+
return handleResponseError(e, outgoing);
|
|
292
285
|
}
|
|
293
286
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
294
287
|
if (res.body) {
|
package/dist/vercel.mjs
CHANGED
|
@@ -240,19 +240,12 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
240
240
|
if (res instanceof Promise) {
|
|
241
241
|
res = await res.catch(handleFetchError);
|
|
242
242
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// @ts-expect-error the object must have `toString()`
|
|
246
|
-
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
247
|
-
outgoing
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
if (cacheKey in res) {
|
|
251
|
-
try {
|
|
243
|
+
try {
|
|
244
|
+
if (cacheKey in res) {
|
|
252
245
|
return responseViaCache(res, outgoing);
|
|
253
|
-
} catch (e) {
|
|
254
|
-
return handleResponseError(e, outgoing);
|
|
255
246
|
}
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return handleResponseError(e, outgoing);
|
|
256
249
|
}
|
|
257
250
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
258
251
|
if (res.body) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/node-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Node.js Adapter for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@types/jest": "^29.5.3",
|
|
67
67
|
"@types/node": "^20.10.0",
|
|
68
68
|
"@types/supertest": "^2.0.12",
|
|
69
|
+
"@whatwg-node/fetch": "^0.9.14",
|
|
69
70
|
"eslint": "^8.55.0",
|
|
70
71
|
"hono": "^3.11.7",
|
|
71
72
|
"jest": "^29.6.1",
|