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.
@@ -17,6 +17,8 @@ var serveStatic = (options = { root: "" }) => {
17
17
  root: options.root,
18
18
  defaultDocument: DEFAULT_DOCUMENT
19
19
  });
20
+ if (!path)
21
+ return await next();
20
22
  path = `./${path}`;
21
23
  if (existsSync(path)) {
22
24
  const content = file(path);
@@ -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
  };
@@ -1,5 +1,6 @@
1
1
  // src/adapter/cloudflare-pages/index.ts
2
- import { handle } from "./handler.js";
2
+ import { handle, serveStatic } from "./handler.js";
3
3
  export {
4
- handle
4
+ handle,
5
+ serveStatic
5
6
  };
@@ -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
@@ -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
  path = `./${path}`;
20
22
  let file;
21
23
  try {
@@ -17,6 +17,7 @@ var handle = (app) => {
17
17
  callback: (err, result) => {
18
18
  callback?.(err, result);
19
19
  },
20
+ config: event.Records[0].cf.config,
20
21
  request: event.Records[0].cf.request,
21
22
  response: event.Records[0].cf.response
22
23
  });
@@ -39,6 +39,8 @@ const serveStatic = (options = { root: "" }) => {
39
39
  root: options.root,
40
40
  defaultDocument: DEFAULT_DOCUMENT
41
41
  });
42
+ if (!path)
43
+ return await next();
42
44
  path = `./${path}`;
43
45
  if ((0, import_fs.existsSync)(path)) {
44
46
  const content = file(path);
@@ -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
@@ -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
  path = `./${path}`;
42
44
  let file;
43
45
  try {
@@ -46,6 +46,7 @@ const handle = (app) => {
46
46
  callback: (err, result) => {
47
47
  callback?.(err, result);
48
48
  },
49
+ config: event.Records[0].cf.config,
49
50
  request: event.Records[0].cf.request,
50
51
  response: event.Records[0].cf.response
51
52
  });
@@ -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("/")) {
@@ -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 = "&quot;";
38
38
  break;
39
+ case 39:
40
+ escape = "&#39;";
41
+ break;
39
42
  case 38:
40
43
  escape = "&amp;";
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<Response | undefined>;
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<Response | undefined>;
8
+ export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<void | Response>;
@@ -37,7 +37,7 @@ export interface CloudFrontResponse {
37
37
  status: string;
38
38
  statusDescription?: string;
39
39
  }
40
- interface CloudFrontConfig {
40
+ export interface CloudFrontConfig {
41
41
  distributionDomainName: string;
42
42
  distributionId: string;
43
43
  eventType: string;
@@ -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';
@@ -3,5 +3,5 @@ declare type FilePathOptions = {
3
3
  root?: string;
4
4
  defaultDocument?: string;
5
5
  };
6
- export declare const getFilePath: (options: FilePathOptions) => string;
6
+ export declare const getFilePath: (options: FilePathOptions) => string | undefined;
7
7
  export {};
@@ -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("/")) {
@@ -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 = "&quot;";
16
16
  break;
17
+ case 39:
18
+ escape = "&#39;";
19
+ break;
17
20
  case 38:
18
21
  escape = "&amp;";
19
22
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",