hono 3.3.3 → 3.3.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/adapter/bun/serve-static.js +2 -0
- package/dist/adapter/cloudflare-pages/handler.js +12 -1
- package/dist/adapter/cloudflare-pages/index.js +3 -2
- package/dist/adapter/cloudflare-workers/serve-static.js +2 -0
- package/dist/adapter/deno/serve-static.js +2 -0
- package/dist/adapter/lambda-edge/handler.js +1 -0
- package/dist/cjs/adapter/bun/serve-static.js +2 -0
- package/dist/cjs/adapter/cloudflare-pages/handler.js +14 -2
- package/dist/cjs/adapter/cloudflare-pages/index.js +4 -2
- package/dist/cjs/adapter/cloudflare-workers/serve-static.js +2 -0
- package/dist/cjs/adapter/deno/serve-static.js +2 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +1 -0
- package/dist/cjs/utils/filepath.js +2 -0
- package/dist/cjs/utils/html.js +4 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +2 -1
- package/dist/types/adapter/bun/serve-static.d.ts +1 -1
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +8 -1
- package/dist/types/adapter/cloudflare-pages/index.d.ts +1 -1
- package/dist/types/adapter/deno/serve-static.d.ts +1 -1
- package/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
- package/dist/types/adapter/lambda-edge/index.d.ts +1 -1
- package/dist/types/utils/filepath.d.ts +1 -1
- package/dist/utils/filepath.js +2 -0
- package/dist/utils/html.js +4 -1
- package/package.json +1 -1
|
@@ -11,6 +11,17 @@ var handle = (subApp, path) => (eventContext) => {
|
|
|
11
11
|
}
|
|
12
12
|
);
|
|
13
13
|
};
|
|
14
|
+
var serveStatic = () => {
|
|
15
|
+
return async (c) => {
|
|
16
|
+
const env = c.env;
|
|
17
|
+
const res = await env.ASSETS.fetch(c.req.raw);
|
|
18
|
+
if (res.status === 404) {
|
|
19
|
+
return c.notFound();
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
14
24
|
export {
|
|
15
|
-
handle
|
|
25
|
+
handle,
|
|
26
|
+
serveStatic
|
|
16
27
|
};
|
|
@@ -16,6 +16,8 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
16
16
|
root: options.root,
|
|
17
17
|
defaultDocument: DEFAULT_DOCUMENT
|
|
18
18
|
});
|
|
19
|
+
if (!path)
|
|
20
|
+
return await next();
|
|
19
21
|
const content = await getContentFromKVAsset(path, {
|
|
20
22
|
manifest: options.manifest,
|
|
21
23
|
namespace: options.namespace ? options.namespace : c.env ? c.env.__STATIC_CONTENT : void 0
|
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var handler_exports = {};
|
|
20
20
|
__export(handler_exports, {
|
|
21
|
-
handle: () => handle
|
|
21
|
+
handle: () => handle,
|
|
22
|
+
serveStatic: () => serveStatic
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(handler_exports);
|
|
24
25
|
var import_hono = require("../../hono");
|
|
@@ -33,7 +34,18 @@ const handle = (subApp, path) => (eventContext) => {
|
|
|
33
34
|
}
|
|
34
35
|
);
|
|
35
36
|
};
|
|
37
|
+
const serveStatic = () => {
|
|
38
|
+
return async (c) => {
|
|
39
|
+
const env = c.env;
|
|
40
|
+
const res = await env.ASSETS.fetch(c.req.raw);
|
|
41
|
+
if (res.status === 404) {
|
|
42
|
+
return c.notFound();
|
|
43
|
+
}
|
|
44
|
+
return res;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
36
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
48
|
0 && (module.exports = {
|
|
38
|
-
handle
|
|
49
|
+
handle,
|
|
50
|
+
serveStatic
|
|
39
51
|
});
|
|
@@ -18,11 +18,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var cloudflare_pages_exports = {};
|
|
20
20
|
__export(cloudflare_pages_exports, {
|
|
21
|
-
handle: () => import_handler.handle
|
|
21
|
+
handle: () => import_handler.handle,
|
|
22
|
+
serveStatic: () => import_handler.serveStatic
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(cloudflare_pages_exports);
|
|
24
25
|
var import_handler = require("./handler");
|
|
25
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
27
|
0 && (module.exports = {
|
|
27
|
-
handle
|
|
28
|
+
handle,
|
|
29
|
+
serveStatic
|
|
28
30
|
});
|
|
@@ -38,6 +38,8 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
38
38
|
root: options.root,
|
|
39
39
|
defaultDocument: DEFAULT_DOCUMENT
|
|
40
40
|
});
|
|
41
|
+
if (!path)
|
|
42
|
+
return await next();
|
|
41
43
|
const content = await (0, import_cloudflare.getContentFromKVAsset)(path, {
|
|
42
44
|
manifest: options.manifest,
|
|
43
45
|
namespace: options.namespace ? options.namespace : c.env ? c.env.__STATIC_CONTENT : void 0
|
|
@@ -23,6 +23,8 @@ __export(filepath_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(filepath_exports);
|
|
24
24
|
const getFilePath = (options) => {
|
|
25
25
|
let filename = options.filename;
|
|
26
|
+
if (/(?:^|\/)\.\.(?:$|\/)/.test(filename))
|
|
27
|
+
return;
|
|
26
28
|
let root = options.root || "";
|
|
27
29
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
28
30
|
if (filename.endsWith("/")) {
|
package/dist/cjs/utils/html.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(html_exports, {
|
|
|
21
21
|
escapeToBuffer: () => escapeToBuffer
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(html_exports);
|
|
24
|
-
const escapeRe = /[&<>"]/;
|
|
24
|
+
const escapeRe = /[&<>'"]/;
|
|
25
25
|
const escapeToBuffer = (str, buffer) => {
|
|
26
26
|
const match = str.search(escapeRe);
|
|
27
27
|
if (match === -1) {
|
|
@@ -36,6 +36,9 @@ const escapeToBuffer = (str, buffer) => {
|
|
|
36
36
|
case 34:
|
|
37
37
|
escape = """;
|
|
38
38
|
break;
|
|
39
|
+
case 39:
|
|
40
|
+
escape = "'";
|
|
41
|
+
break;
|
|
39
42
|
case 38:
|
|
40
43
|
escape = "&";
|
|
41
44
|
break;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
|
+
import type { Env } from '../../types';
|
|
2
3
|
interface APIGatewayProxyEventV2 {
|
|
3
4
|
httpMethod: string;
|
|
4
5
|
headers: Record<string, string | undefined>;
|
|
@@ -43,6 +44,6 @@ interface APIGatewayProxyResult {
|
|
|
43
44
|
/**
|
|
44
45
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
45
46
|
*/
|
|
46
|
-
export declare const handle: (app: Hono) => (event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent) => Promise<APIGatewayProxyResult>;
|
|
47
|
+
export declare const handle: <E extends Env = Env, S = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => (event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent) => Promise<APIGatewayProxyResult>;
|
|
47
48
|
export declare const isContentTypeBinary: (contentType: string) => boolean;
|
|
48
49
|
export {};
|
|
@@ -5,4 +5,4 @@ export declare type ServeStaticOptions = {
|
|
|
5
5
|
path?: string;
|
|
6
6
|
rewriteRequestPath?: (path: string) => string;
|
|
7
7
|
};
|
|
8
|
-
export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<
|
|
8
|
+
export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<void | Response>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from '../../hono';
|
|
2
|
-
import type { Env } from '../../types';
|
|
2
|
+
import type { Env, MiddlewareHandler } from '../../types';
|
|
3
3
|
declare type Params<P extends string = any> = Record<P, string | string[]>;
|
|
4
4
|
export declare type EventContext<Env = {}, P extends string = any, Data = {}> = {
|
|
5
5
|
request: Request;
|
|
@@ -24,4 +24,11 @@ interface HandleInterface {
|
|
|
24
24
|
<E extends Env, S extends {}, BasePath extends string>(app: Hono<E, S, BasePath>, path: string): (eventContext: EventContext) => Response | Promise<Response>;
|
|
25
25
|
}
|
|
26
26
|
export declare const handle: HandleInterface;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @description `serveStatic()` is for advanced mode:
|
|
30
|
+
* https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export declare const serveStatic: () => MiddlewareHandler;
|
|
27
34
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { handle } from './handler';
|
|
1
|
+
export { handle, serveStatic } from './handler';
|
|
2
2
|
export type { EventContext } from './handler';
|
|
@@ -5,4 +5,4 @@ export declare type ServeStaticOptions = {
|
|
|
5
5
|
path?: string;
|
|
6
6
|
rewriteRequestPath?: (path: string) => string;
|
|
7
7
|
};
|
|
8
|
-
export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<
|
|
8
|
+
export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<void | Response>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { handle } from './handler';
|
|
2
|
-
export type { Callback, CloudFrontRequest, CloudFrontEdgeEvent } from './handler';
|
|
2
|
+
export type { Callback, CloudFrontConfig, CloudFrontRequest, CloudFrontResponse, CloudFrontEdgeEvent } from './handler';
|
package/dist/utils/filepath.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/utils/filepath.ts
|
|
2
2
|
var getFilePath = (options) => {
|
|
3
3
|
let filename = options.filename;
|
|
4
|
+
if (/(?:^|\/)\.\.(?:$|\/)/.test(filename))
|
|
5
|
+
return;
|
|
4
6
|
let root = options.root || "";
|
|
5
7
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
6
8
|
if (filename.endsWith("/")) {
|
package/dist/utils/html.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/utils/html.ts
|
|
2
|
-
var escapeRe = /[&<>"]/;
|
|
2
|
+
var escapeRe = /[&<>'"]/;
|
|
3
3
|
var escapeToBuffer = (str, buffer) => {
|
|
4
4
|
const match = str.search(escapeRe);
|
|
5
5
|
if (match === -1) {
|
|
@@ -14,6 +14,9 @@ var escapeToBuffer = (str, buffer) => {
|
|
|
14
14
|
case 34:
|
|
15
15
|
escape = """;
|
|
16
16
|
break;
|
|
17
|
+
case 39:
|
|
18
|
+
escape = "'";
|
|
19
|
+
break;
|
|
17
20
|
case 38:
|
|
18
21
|
escape = "&";
|
|
19
22
|
break;
|