@rdlabo/workers-hono-kit 0.3.2 → 0.3.3
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/http/trailing-slash.d.ts +21 -0
- package/dist/http/trailing-slash.js +28 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/http/trailing-slash.ts +28 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailing-slash normalization for NestJS(Express) → Hono parity.
|
|
3
|
+
*
|
|
4
|
+
* Express runs with strict routing off by default, so `/x` and `/x/` resolve to the same handler.
|
|
5
|
+
* Hono distinguishes them, so a client that sends e.g. `GET /functions/timeline/` 404s against a
|
|
6
|
+
* Hono worker that only registered `/functions/timeline`. Apply this at the Worker `fetch` entry to
|
|
7
|
+
* strip a trailing slash before routing, preserving method / headers / body.
|
|
8
|
+
*
|
|
9
|
+
* We intentionally do NOT use `hono/trailing-slash`'s `trimTrailingSlash`, which responds with a 301
|
|
10
|
+
* redirect and thus breaks non-GET methods (POST/PUT/DELETE) and clients that don't follow redirects.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* export default {
|
|
14
|
+
* fetch: (request, env, ctx) => app.fetch(normalizeTrailingSlash(request), env, ctx),
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* @param request - The incoming request.
|
|
18
|
+
* @returns The same request when the path has no trailing slash (or is exactly `/`), otherwise a new
|
|
19
|
+
* Request with the trailing slash(es) removed.
|
|
20
|
+
*/
|
|
21
|
+
export declare const normalizeTrailingSlash: (request: Request) => Request;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailing-slash normalization for NestJS(Express) → Hono parity.
|
|
3
|
+
*
|
|
4
|
+
* Express runs with strict routing off by default, so `/x` and `/x/` resolve to the same handler.
|
|
5
|
+
* Hono distinguishes them, so a client that sends e.g. `GET /functions/timeline/` 404s against a
|
|
6
|
+
* Hono worker that only registered `/functions/timeline`. Apply this at the Worker `fetch` entry to
|
|
7
|
+
* strip a trailing slash before routing, preserving method / headers / body.
|
|
8
|
+
*
|
|
9
|
+
* We intentionally do NOT use `hono/trailing-slash`'s `trimTrailingSlash`, which responds with a 301
|
|
10
|
+
* redirect and thus breaks non-GET methods (POST/PUT/DELETE) and clients that don't follow redirects.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* export default {
|
|
14
|
+
* fetch: (request, env, ctx) => app.fetch(normalizeTrailingSlash(request), env, ctx),
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* @param request - The incoming request.
|
|
18
|
+
* @returns The same request when the path has no trailing slash (or is exactly `/`), otherwise a new
|
|
19
|
+
* Request with the trailing slash(es) removed.
|
|
20
|
+
*/
|
|
21
|
+
export const normalizeTrailingSlash = (request) => {
|
|
22
|
+
const url = new URL(request.url);
|
|
23
|
+
if (url.pathname.length > 1 && url.pathname.endsWith('/')) {
|
|
24
|
+
url.pathname = url.pathname.replace(/\/+$/, '');
|
|
25
|
+
return new Request(url, request);
|
|
26
|
+
}
|
|
27
|
+
return request;
|
|
28
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type { AppEnv } from './http/app-env.js';
|
|
|
24
24
|
export { HttpStatus } from './http/http-status.js';
|
|
25
25
|
export { createNestErrorHandler, nestNotFoundHandler, NEST_REASON_PHRASES } from './http/nest-error.js';
|
|
26
26
|
export type { NestErrorHandlerOptions, ErrorReportContext, ErrorReporter } from './http/nest-error.js';
|
|
27
|
+
export { normalizeTrailingSlash } from './http/trailing-slash.js';
|
|
27
28
|
export { KVCache } from './cache/kv-cache.js';
|
|
28
29
|
export type { KVNamespace, KVCacheOptions } from './cache/kv-cache.js';
|
|
29
30
|
export { createStripeClient, verifyStripeWebhook } from './stripe/client.js';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export { getAppInfo } from './http/app-info.js';
|
|
|
20
20
|
export { resolveAppEnv, isProductionEnv } from './http/app-env.js';
|
|
21
21
|
export { HttpStatus } from './http/http-status.js';
|
|
22
22
|
export { createNestErrorHandler, nestNotFoundHandler, NEST_REASON_PHRASES } from './http/nest-error.js';
|
|
23
|
+
export { normalizeTrailingSlash } from './http/trailing-slash.js';
|
|
23
24
|
// cache
|
|
24
25
|
export { KVCache } from './cache/kv-cache.js';
|
|
25
26
|
// stripe
|
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailing-slash normalization for NestJS(Express) → Hono parity.
|
|
3
|
+
*
|
|
4
|
+
* Express runs with strict routing off by default, so `/x` and `/x/` resolve to the same handler.
|
|
5
|
+
* Hono distinguishes them, so a client that sends e.g. `GET /functions/timeline/` 404s against a
|
|
6
|
+
* Hono worker that only registered `/functions/timeline`. Apply this at the Worker `fetch` entry to
|
|
7
|
+
* strip a trailing slash before routing, preserving method / headers / body.
|
|
8
|
+
*
|
|
9
|
+
* We intentionally do NOT use `hono/trailing-slash`'s `trimTrailingSlash`, which responds with a 301
|
|
10
|
+
* redirect and thus breaks non-GET methods (POST/PUT/DELETE) and clients that don't follow redirects.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* export default {
|
|
14
|
+
* fetch: (request, env, ctx) => app.fetch(normalizeTrailingSlash(request), env, ctx),
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* @param request - The incoming request.
|
|
18
|
+
* @returns The same request when the path has no trailing slash (or is exactly `/`), otherwise a new
|
|
19
|
+
* Request with the trailing slash(es) removed.
|
|
20
|
+
*/
|
|
21
|
+
export const normalizeTrailingSlash = (request: Request): Request => {
|
|
22
|
+
const url = new URL(request.url);
|
|
23
|
+
if (url.pathname.length > 1 && url.pathname.endsWith('/')) {
|
|
24
|
+
url.pathname = url.pathname.replace(/\/+$/, '');
|
|
25
|
+
return new Request(url, request);
|
|
26
|
+
}
|
|
27
|
+
return request;
|
|
28
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type { AppEnv } from './http/app-env.js';
|
|
|
34
34
|
export { HttpStatus } from './http/http-status.js';
|
|
35
35
|
export { createNestErrorHandler, nestNotFoundHandler, NEST_REASON_PHRASES } from './http/nest-error.js';
|
|
36
36
|
export type { NestErrorHandlerOptions, ErrorReportContext, ErrorReporter } from './http/nest-error.js';
|
|
37
|
+
export { normalizeTrailingSlash } from './http/trailing-slash.js';
|
|
37
38
|
|
|
38
39
|
// cache
|
|
39
40
|
export { KVCache } from './cache/kv-cache.js';
|