hono 1.3.2 → 1.3.5
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 +12 -2
- package/dist/compose.js +5 -9
- package/dist/context.js +7 -11
- package/dist/hono.js +15 -18
- package/dist/middleware/mustache/index.d.ts +1 -7
- package/dist/middleware/mustache/index.js +2 -48
- package/dist/middleware/mustache/module.d.mts +3 -0
- package/dist/middleware/mustache/module.mjs +12 -0
- package/dist/middleware/mustache/mustache.d.ts +8 -0
- package/dist/middleware/mustache/mustache.js +45 -0
- package/dist/middleware/serve-static/index.d.ts +1 -7
- package/dist/middleware/serve-static/index.js +2 -32
- package/dist/middleware/serve-static/module.d.mts +3 -0
- package/dist/middleware/serve-static/module.mjs +12 -0
- package/dist/middleware/serve-static/serve-static.d.ts +8 -0
- package/dist/middleware/serve-static/serve-static.js +34 -0
- package/dist/router/trie-router/index.js +1 -5
- package/dist/router/trie-router/node.js +8 -12
- package/dist/router/trie-router/router.js +4 -8
- package/dist/router.js +4 -9
- package/dist/utils/buffer.js +5 -11
- package/dist/utils/cloudflare.d.ts +8 -3
- package/dist/utils/cloudflare.js +26 -15
- package/dist/utils/crypto.js +5 -20
- package/dist/utils/encode.js +0 -26
- package/dist/utils/http-status.js +1 -5
- package/dist/utils/mime.js +1 -5
- package/dist/utils/url.js +5 -13
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -510,6 +510,16 @@ test('GET /hello is ok', async () => {
|
|
|
510
510
|
})
|
|
511
511
|
```
|
|
512
512
|
|
|
513
|
+
## routerClass
|
|
514
|
+
|
|
515
|
+
The `routerClass` option specify which router is used inside. The default router is `TrieRouter`. If you want to use `RexExpRouter`, write like this:
|
|
516
|
+
|
|
517
|
+
```ts
|
|
518
|
+
import { RegExpRouter } from 'hono/router/reg-exp-router'
|
|
519
|
+
|
|
520
|
+
const app = new Hono({ routerClass: RegExpRouter })
|
|
521
|
+
```
|
|
522
|
+
|
|
513
523
|
## Cloudflare Workers with Hono
|
|
514
524
|
|
|
515
525
|
Using [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/), you can develop the application locally and publish it with few commands.
|
|
@@ -584,7 +594,7 @@ import { Hono } from 'hono'
|
|
|
584
594
|
import { cors } from 'hono/cors'
|
|
585
595
|
import { basicAuth } from 'hono/basic-auth'
|
|
586
596
|
import { prettyJSON } from 'hono/pretty-json'
|
|
587
|
-
import { getPosts,
|
|
597
|
+
import { getPosts, getPost, createPost, Post } from './model'
|
|
588
598
|
|
|
589
599
|
const app = new Hono()
|
|
590
600
|
app.get('/', (c) => c.text('Pretty Blog API'))
|
|
@@ -617,7 +627,7 @@ api.post(
|
|
|
617
627
|
await auth(c, next)
|
|
618
628
|
},
|
|
619
629
|
async (c) => {
|
|
620
|
-
const post = await c.req.json<
|
|
630
|
+
const post = await c.req.json<Post>()
|
|
621
631
|
const ok = createPost({ post })
|
|
622
632
|
return c.json({ ok })
|
|
623
633
|
}
|
package/dist/compose.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compose = void 0;
|
|
4
|
-
const context_1 = require("./context");
|
|
1
|
+
import { Context } from './context';
|
|
5
2
|
// Based on the code in the MIT licensed `koa-compose` package.
|
|
6
|
-
const compose = (middleware, onError, onNotFound) => {
|
|
3
|
+
export const compose = (middleware, onError, onNotFound) => {
|
|
7
4
|
return async (context, next) => {
|
|
8
5
|
let index = -1;
|
|
9
6
|
return dispatch(0);
|
|
@@ -16,7 +13,7 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
16
13
|
if (i === middleware.length)
|
|
17
14
|
handler = next;
|
|
18
15
|
if (handler === undefined) {
|
|
19
|
-
if (context instanceof
|
|
16
|
+
if (context instanceof Context && context.res === undefined) {
|
|
20
17
|
context.res = onNotFound(context);
|
|
21
18
|
}
|
|
22
19
|
return Promise.resolve(context);
|
|
@@ -24,14 +21,14 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
24
21
|
return Promise.resolve(handler(context, dispatch.bind(null, i + 1)))
|
|
25
22
|
.then(async (res) => {
|
|
26
23
|
// If handler return Response like `return c.text('foo')`
|
|
27
|
-
if (res && context instanceof
|
|
24
|
+
if (res && context instanceof Context) {
|
|
28
25
|
context.res = res;
|
|
29
26
|
dispatch(i + 1); // <--- Call next()
|
|
30
27
|
}
|
|
31
28
|
return context;
|
|
32
29
|
})
|
|
33
30
|
.catch((err) => {
|
|
34
|
-
if (onError && context instanceof
|
|
31
|
+
if (onError && context instanceof Context) {
|
|
35
32
|
if (err instanceof Error) {
|
|
36
33
|
context.res = onError(err, context);
|
|
37
34
|
}
|
|
@@ -44,4 +41,3 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
44
41
|
}
|
|
45
42
|
};
|
|
46
43
|
};
|
|
47
|
-
exports.compose = compose;
|
package/dist/context.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const http_status_1 = require("./utils/http-status");
|
|
5
|
-
const url_1 = require("./utils/url");
|
|
6
|
-
class Context {
|
|
1
|
+
import { getStatusText } from './utils/http-status';
|
|
2
|
+
import { isAbsoluteURL } from './utils/url';
|
|
3
|
+
export class Context {
|
|
7
4
|
constructor(req, opts) {
|
|
8
5
|
this.res = undefined;
|
|
9
6
|
this._headers = {};
|
|
@@ -51,7 +48,7 @@ class Context {
|
|
|
51
48
|
}
|
|
52
49
|
status(status) {
|
|
53
50
|
this._status = status;
|
|
54
|
-
this._statusText =
|
|
51
|
+
this._statusText = getStatusText(status);
|
|
55
52
|
}
|
|
56
53
|
set(key, value) {
|
|
57
54
|
this._map[key] = value;
|
|
@@ -66,8 +63,8 @@ class Context {
|
|
|
66
63
|
newResponse(data, init = {}) {
|
|
67
64
|
init.status = init.status || this._status || 200;
|
|
68
65
|
init.statusText =
|
|
69
|
-
init.statusText || this._statusText ||
|
|
70
|
-
init.headers =
|
|
66
|
+
init.statusText || this._statusText || getStatusText(init.status);
|
|
67
|
+
init.headers = { ...this._headers, ...init.headers };
|
|
71
68
|
return new Response(data, init);
|
|
72
69
|
}
|
|
73
70
|
body(data, status = this._status, headers = this._headers) {
|
|
@@ -104,7 +101,7 @@ class Context {
|
|
|
104
101
|
if (typeof location !== 'string') {
|
|
105
102
|
throw new TypeError('location must be a string!');
|
|
106
103
|
}
|
|
107
|
-
if (!
|
|
104
|
+
if (!isAbsoluteURL(location)) {
|
|
108
105
|
const url = new URL(this.req.url);
|
|
109
106
|
url.pathname = location;
|
|
110
107
|
location = url.toString();
|
|
@@ -117,4 +114,3 @@ class Context {
|
|
|
117
114
|
});
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
|
-
exports.Context = Context;
|
package/dist/hono.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const router_2 = require("./router");
|
|
8
|
-
const trie_router_1 = require("./router/trie-router"); // Default Router
|
|
9
|
-
const url_1 = require("./utils/url");
|
|
1
|
+
import { compose } from './compose';
|
|
2
|
+
import { Context } from './context';
|
|
3
|
+
import { METHOD_NAME_ALL } from './router';
|
|
4
|
+
import { METHOD_NAME_ALL_LOWERCASE } from './router';
|
|
5
|
+
import { TrieRouter } from './router/trie-router'; // Default Router
|
|
6
|
+
import { getPathFromURL, mergePath } from './utils/url';
|
|
10
7
|
const methods = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch'];
|
|
11
8
|
function defineDynamicClass() {
|
|
12
9
|
return class {
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
|
-
class Hono extends defineDynamicClass() {
|
|
12
|
+
export class Hono extends defineDynamicClass() {
|
|
16
13
|
constructor(init = {}) {
|
|
17
14
|
super();
|
|
18
|
-
this.routerClass =
|
|
15
|
+
this.routerClass = TrieRouter;
|
|
19
16
|
this.strict = true; // strict routing - default is true
|
|
20
17
|
this.path = '/';
|
|
21
18
|
this.routes = [];
|
|
@@ -28,7 +25,7 @@ class Hono extends defineDynamicClass() {
|
|
|
28
25
|
const message = 'Internal Server Error';
|
|
29
26
|
return c.text(message, 500);
|
|
30
27
|
};
|
|
31
|
-
const allMethods = [...methods,
|
|
28
|
+
const allMethods = [...methods, METHOD_NAME_ALL_LOWERCASE];
|
|
32
29
|
allMethods.map((method) => {
|
|
33
30
|
this[method] = (args1, ...args) => {
|
|
34
31
|
if (typeof args1 === 'string') {
|
|
@@ -55,6 +52,7 @@ class Hono extends defineDynamicClass() {
|
|
|
55
52
|
app.routes.map((r) => {
|
|
56
53
|
this.addRoute(r.method, r.path, r.handler);
|
|
57
54
|
});
|
|
55
|
+
this._tempPath = null;
|
|
58
56
|
}
|
|
59
57
|
return this;
|
|
60
58
|
}
|
|
@@ -66,7 +64,7 @@ class Hono extends defineDynamicClass() {
|
|
|
66
64
|
handlers.unshift(arg1);
|
|
67
65
|
}
|
|
68
66
|
handlers.map((handler) => {
|
|
69
|
-
this.addRoute(
|
|
67
|
+
this.addRoute(METHOD_NAME_ALL, this.path, handler);
|
|
70
68
|
});
|
|
71
69
|
return this;
|
|
72
70
|
}
|
|
@@ -81,7 +79,7 @@ class Hono extends defineDynamicClass() {
|
|
|
81
79
|
addRoute(method, path, handler) {
|
|
82
80
|
method = method.toUpperCase();
|
|
83
81
|
if (this._tempPath) {
|
|
84
|
-
path =
|
|
82
|
+
path = mergePath(this._tempPath, path);
|
|
85
83
|
}
|
|
86
84
|
this._router.add(method, path, handler);
|
|
87
85
|
const r = { path: path, method: method, handler: handler };
|
|
@@ -91,7 +89,7 @@ class Hono extends defineDynamicClass() {
|
|
|
91
89
|
return this._router.match(method, path);
|
|
92
90
|
}
|
|
93
91
|
async dispatch(request, event, env) {
|
|
94
|
-
const path =
|
|
92
|
+
const path = getPathFromURL(request.url, { strict: this.strict });
|
|
95
93
|
const method = request.method;
|
|
96
94
|
const result = await this.matchRoute(method, path);
|
|
97
95
|
request.param = ((key) => {
|
|
@@ -105,9 +103,9 @@ class Hono extends defineDynamicClass() {
|
|
|
105
103
|
}
|
|
106
104
|
});
|
|
107
105
|
const handlers = result ? result.handlers : [this.notFoundHandler];
|
|
108
|
-
const c = new
|
|
106
|
+
const c = new Context(request, { env: env, event: event, res: undefined });
|
|
109
107
|
c.notFound = () => this.notFoundHandler(c);
|
|
110
|
-
const composed =
|
|
108
|
+
const composed = compose(handlers, this.errorHandler, this.notFoundHandler);
|
|
111
109
|
let context;
|
|
112
110
|
try {
|
|
113
111
|
context = await composed(c);
|
|
@@ -137,4 +135,3 @@ class Hono extends defineDynamicClass() {
|
|
|
137
135
|
});
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
|
-
exports.Hono = Hono;
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Next } from '../../hono';
|
|
3
|
-
declare type Init = {
|
|
4
|
-
root: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const mustache: (init?: Init) => (c: Context, next: Next) => Promise<void>;
|
|
7
|
-
export {};
|
|
1
|
+
export { mustache } from './mustache';
|
|
@@ -1,51 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mustache = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const EXTENSION = '.mustache';
|
|
7
|
-
const DEFAULT_DOCUMENT = 'index.mustache';
|
|
8
|
-
const mustache = (init = { root: '' }) => {
|
|
9
|
-
const { root } = init;
|
|
10
|
-
return async (c, next) => {
|
|
11
|
-
let Mustache;
|
|
12
|
-
try {
|
|
13
|
-
Mustache = require('mustache');
|
|
14
|
-
}
|
|
15
|
-
catch (_a) {
|
|
16
|
-
throw new Error('If you want to use Mustache Middleware, install "mustache" package first.');
|
|
17
|
-
}
|
|
18
|
-
c.render = async (filename, params = {}, options) => {
|
|
19
|
-
const path = (0, cloudflare_1.getKVFilePath)({
|
|
20
|
-
filename: `${filename}${EXTENSION}`,
|
|
21
|
-
root: root,
|
|
22
|
-
defaultDocument: DEFAULT_DOCUMENT,
|
|
23
|
-
});
|
|
24
|
-
const buffer = await (0, cloudflare_1.getContentFromKVAsset)(path);
|
|
25
|
-
if (!buffer) {
|
|
26
|
-
throw new Error(`Template "${path}" is not found or blank.`);
|
|
27
|
-
}
|
|
28
|
-
const content = (0, buffer_1.bufferToString)(buffer);
|
|
29
|
-
const partialArgs = {};
|
|
30
|
-
if (options) {
|
|
31
|
-
const partials = options;
|
|
32
|
-
for (const key of Object.keys(partials)) {
|
|
33
|
-
const partialPath = (0, cloudflare_1.getKVFilePath)({
|
|
34
|
-
filename: `${partials[key]}${EXTENSION}`,
|
|
35
|
-
root: root,
|
|
36
|
-
defaultDocument: DEFAULT_DOCUMENT,
|
|
37
|
-
});
|
|
38
|
-
const partialBuffer = await (0, cloudflare_1.getContentFromKVAsset)(partialPath);
|
|
39
|
-
if (!partialBuffer) {
|
|
40
|
-
throw new Error(`Partial Template "${partialPath}" is not found or blank.`);
|
|
41
|
-
}
|
|
42
|
-
partialArgs[key] = (0, buffer_1.bufferToString)(partialBuffer);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const output = Mustache.render(content, params, partialArgs);
|
|
46
|
-
return c.html(output);
|
|
47
|
-
};
|
|
48
|
-
await next();
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
exports.mustache = mustache;
|
|
4
|
+
var mustache_1 = require("./mustache");
|
|
5
|
+
Object.defineProperty(exports, "mustache", { enumerable: true, get: function () { return mustache_1.mustache; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
// For ES module mode
|
|
4
|
+
import manifest from '__STATIC_CONTENT_MANIFEST';
|
|
5
|
+
import { mustache } from './mustache';
|
|
6
|
+
const module = (options = { root: '' }) => {
|
|
7
|
+
return mustache({
|
|
8
|
+
root: options.root,
|
|
9
|
+
manifest: options.manifest ? options.manifest : manifest,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export { module as mustache };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import type { Handler } from '../../hono';
|
|
3
|
+
export declare type MustacheOptions = {
|
|
4
|
+
root: string;
|
|
5
|
+
manifest?: object | string;
|
|
6
|
+
namespace?: KVNamespace;
|
|
7
|
+
};
|
|
8
|
+
export declare const mustache: (init?: MustacheOptions) => Handler;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Mustache from 'mustache';
|
|
2
|
+
import { bufferToString } from '../../utils/buffer';
|
|
3
|
+
import { getContentFromKVAsset, getKVFilePath } from '../../utils/cloudflare';
|
|
4
|
+
const EXTENSION = '.mustache';
|
|
5
|
+
const DEFAULT_DOCUMENT = 'index.mustache';
|
|
6
|
+
export const mustache = (init = { root: '' }) => {
|
|
7
|
+
const { root } = init;
|
|
8
|
+
return async (c, next) => {
|
|
9
|
+
c.render = async (filename, params = {}, options) => {
|
|
10
|
+
const path = getKVFilePath({
|
|
11
|
+
filename: `${filename}${EXTENSION}`,
|
|
12
|
+
root: root,
|
|
13
|
+
defaultDocument: DEFAULT_DOCUMENT,
|
|
14
|
+
});
|
|
15
|
+
const kvAssetOptions = {
|
|
16
|
+
manifest: init.manifest,
|
|
17
|
+
namespace: init.namespace ? init.namespace : c.env ? c.env.__STATIC_CONTENT : undefined,
|
|
18
|
+
};
|
|
19
|
+
const buffer = await getContentFromKVAsset(path, kvAssetOptions);
|
|
20
|
+
if (!buffer) {
|
|
21
|
+
throw new Error(`Template "${path}" is not found or blank.`);
|
|
22
|
+
}
|
|
23
|
+
const content = bufferToString(buffer);
|
|
24
|
+
const partialArgs = {};
|
|
25
|
+
if (options) {
|
|
26
|
+
const partials = options;
|
|
27
|
+
for (const key of Object.keys(partials)) {
|
|
28
|
+
const partialPath = getKVFilePath({
|
|
29
|
+
filename: `${partials[key]}${EXTENSION}`,
|
|
30
|
+
root: root,
|
|
31
|
+
defaultDocument: DEFAULT_DOCUMENT,
|
|
32
|
+
});
|
|
33
|
+
const partialBuffer = await getContentFromKVAsset(partialPath, kvAssetOptions);
|
|
34
|
+
if (!partialBuffer) {
|
|
35
|
+
throw new Error(`Partial Template "${partialPath}" is not found or blank.`);
|
|
36
|
+
}
|
|
37
|
+
partialArgs[key] = bufferToString(partialBuffer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const output = Mustache.render(content, params, partialArgs);
|
|
41
|
+
return c.html(output);
|
|
42
|
+
};
|
|
43
|
+
await next();
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Next } from '../../hono';
|
|
3
|
-
declare type Options = {
|
|
4
|
-
root: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const serveStatic: (opt?: Options) => (c: Context, next: Next) => Promise<Response>;
|
|
7
|
-
export {};
|
|
1
|
+
export { serveStatic } from './serve-static';
|
|
@@ -1,35 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serveStatic = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const DEFAULT_DOCUMENT = 'index.html';
|
|
7
|
-
// This middleware is available only on Cloudflare Workers.
|
|
8
|
-
const serveStatic = (opt = { root: '' }) => {
|
|
9
|
-
return async (c, next) => {
|
|
10
|
-
// Do nothing if Response is already set
|
|
11
|
-
if (c.res) {
|
|
12
|
-
await next();
|
|
13
|
-
}
|
|
14
|
-
const url = new URL(c.req.url);
|
|
15
|
-
const path = (0, cloudflare_1.getKVFilePath)({
|
|
16
|
-
filename: url.pathname,
|
|
17
|
-
root: opt.root,
|
|
18
|
-
defaultDocument: DEFAULT_DOCUMENT,
|
|
19
|
-
});
|
|
20
|
-
const content = await (0, cloudflare_1.getContentFromKVAsset)(path);
|
|
21
|
-
if (content) {
|
|
22
|
-
const mimeType = (0, mime_1.getMimeType)(path);
|
|
23
|
-
if (mimeType) {
|
|
24
|
-
c.header('Content-Type', mimeType);
|
|
25
|
-
}
|
|
26
|
-
// Return Response object
|
|
27
|
-
return c.body(content);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
console.warn(`Static file: ${path} is not found`);
|
|
31
|
-
await next();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
exports.serveStatic = serveStatic;
|
|
4
|
+
var serve_static_1 = require("./serve-static");
|
|
5
|
+
Object.defineProperty(exports, "serveStatic", { enumerable: true, get: function () { return serve_static_1.serveStatic; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
// For ES module mode
|
|
4
|
+
import manifest from '__STATIC_CONTENT_MANIFEST';
|
|
5
|
+
import { serveStatic } from './serve-static';
|
|
6
|
+
const module = (options = { root: '' }) => {
|
|
7
|
+
return serveStatic({
|
|
8
|
+
root: options.root,
|
|
9
|
+
manifest: options.manifest ? options.manifest : manifest,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export { module as serveStatic };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import type { Handler } from '../../hono';
|
|
3
|
+
export declare type ServeStaticOptions = {
|
|
4
|
+
root: string;
|
|
5
|
+
manifest?: object | string;
|
|
6
|
+
namespace?: KVNamespace;
|
|
7
|
+
};
|
|
8
|
+
export declare const serveStatic: (options?: ServeStaticOptions) => Handler;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getContentFromKVAsset, getKVFilePath } from '../../utils/cloudflare';
|
|
2
|
+
import { getMimeType } from '../../utils/mime';
|
|
3
|
+
const DEFAULT_DOCUMENT = 'index.html';
|
|
4
|
+
// This middleware is available only on Cloudflare Workers.
|
|
5
|
+
export const serveStatic = (options = { root: '' }) => {
|
|
6
|
+
return async (c, next) => {
|
|
7
|
+
// Do nothing if Response is already set
|
|
8
|
+
if (c.res) {
|
|
9
|
+
await next();
|
|
10
|
+
}
|
|
11
|
+
const url = new URL(c.req.url);
|
|
12
|
+
const path = getKVFilePath({
|
|
13
|
+
filename: url.pathname,
|
|
14
|
+
root: options.root,
|
|
15
|
+
defaultDocument: DEFAULT_DOCUMENT,
|
|
16
|
+
});
|
|
17
|
+
const content = await getContentFromKVAsset(path, {
|
|
18
|
+
manifest: options.manifest,
|
|
19
|
+
namespace: options.namespace ? options.namespace : c.env ? c.env.__STATIC_CONTENT : undefined,
|
|
20
|
+
});
|
|
21
|
+
if (content) {
|
|
22
|
+
const mimeType = getMimeType(path);
|
|
23
|
+
if (mimeType) {
|
|
24
|
+
c.header('Content-Type', mimeType);
|
|
25
|
+
}
|
|
26
|
+
// Return Response object
|
|
27
|
+
return c.body(content);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.warn(`Static file: ${path} is not found`);
|
|
31
|
+
await next();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrieRouter = void 0;
|
|
4
|
-
var router_1 = require("./router");
|
|
5
|
-
Object.defineProperty(exports, "TrieRouter", { enumerable: true, get: function () { return router_1.TrieRouter; } });
|
|
1
|
+
export { TrieRouter } from './router';
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Node = void 0;
|
|
4
|
-
const router_1 = require("../../router");
|
|
5
|
-
const url_1 = require("../../utils/url");
|
|
1
|
+
import { Result, METHOD_NAME_ALL } from '../../router';
|
|
2
|
+
import { splitPath, getPattern } from '../../utils/url';
|
|
6
3
|
function findParam(node, name) {
|
|
7
4
|
for (let i = 0, len = node.patterns.length; i < len; i++) {
|
|
8
5
|
if (typeof node.patterns[i] === 'object' && node.patterns[i][1] === name) {
|
|
@@ -17,7 +14,7 @@ function findParam(node, name) {
|
|
|
17
14
|
}
|
|
18
15
|
return false;
|
|
19
16
|
}
|
|
20
|
-
class Node {
|
|
17
|
+
export class Node {
|
|
21
18
|
constructor(method, handler, children) {
|
|
22
19
|
this.children = children || {};
|
|
23
20
|
this.methods = [];
|
|
@@ -31,7 +28,7 @@ class Node {
|
|
|
31
28
|
insert(method, path, handler) {
|
|
32
29
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
33
30
|
let curNode = this;
|
|
34
|
-
const parts =
|
|
31
|
+
const parts = splitPath(path);
|
|
35
32
|
const parentPatterns = [];
|
|
36
33
|
const errorMessage = (name) => {
|
|
37
34
|
return `Duplicate param name, use another name instead of '${name}' - ${method} ${path} <--- '${name}'`;
|
|
@@ -44,7 +41,7 @@ class Node {
|
|
|
44
41
|
continue;
|
|
45
42
|
}
|
|
46
43
|
curNode.children[p] = new Node();
|
|
47
|
-
const pattern =
|
|
44
|
+
const pattern = getPattern(p);
|
|
48
45
|
if (pattern) {
|
|
49
46
|
if (typeof pattern === 'object') {
|
|
50
47
|
for (let j = 0, len = parentPatterns.length; j < len; j++) {
|
|
@@ -78,7 +75,7 @@ class Node {
|
|
|
78
75
|
handlers.push(handler);
|
|
79
76
|
return;
|
|
80
77
|
}
|
|
81
|
-
handler = m[
|
|
78
|
+
handler = m[METHOD_NAME_ALL];
|
|
82
79
|
if (handler !== undefined) {
|
|
83
80
|
handlers.push(handler);
|
|
84
81
|
return;
|
|
@@ -142,7 +139,7 @@ class Node {
|
|
|
142
139
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
143
140
|
const curNode = this;
|
|
144
141
|
let curNodes = [curNode];
|
|
145
|
-
const parts =
|
|
142
|
+
const parts = splitPath(path);
|
|
146
143
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
147
144
|
const p = parts[i];
|
|
148
145
|
const isLast = i === len - 1;
|
|
@@ -160,7 +157,6 @@ class Node {
|
|
|
160
157
|
}
|
|
161
158
|
if (handlers.length <= 0)
|
|
162
159
|
return null;
|
|
163
|
-
return new
|
|
160
|
+
return new Result(handlers, params);
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
|
-
exports.Node = Node;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const router_1 = require("../../router");
|
|
5
|
-
const node_1 = require("./node");
|
|
6
|
-
class TrieRouter extends router_1.Router {
|
|
1
|
+
import { Router } from '../../router';
|
|
2
|
+
import { Node } from './node';
|
|
3
|
+
export class TrieRouter extends Router {
|
|
7
4
|
constructor() {
|
|
8
5
|
super();
|
|
9
|
-
this.node = new
|
|
6
|
+
this.node = new Node();
|
|
10
7
|
}
|
|
11
8
|
add(method, path, handler) {
|
|
12
9
|
this.node.insert(method, path, handler);
|
|
@@ -15,4 +12,3 @@ class TrieRouter extends router_1.Router {
|
|
|
15
12
|
return this.node.search(method, path);
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.TrieRouter = TrieRouter;
|
package/dist/router.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.METHOD_NAME_ALL = 'ALL';
|
|
5
|
-
exports.METHOD_NAME_ALL_LOWERCASE = 'all';
|
|
6
|
-
class Router {
|
|
1
|
+
export const METHOD_NAME_ALL = 'ALL';
|
|
2
|
+
export const METHOD_NAME_ALL_LOWERCASE = 'all';
|
|
3
|
+
export class Router {
|
|
7
4
|
}
|
|
8
|
-
|
|
9
|
-
class Result {
|
|
5
|
+
export class Result {
|
|
10
6
|
constructor(handlers, params) {
|
|
11
7
|
this.handlers = handlers;
|
|
12
8
|
this.params = params;
|
|
13
9
|
}
|
|
14
10
|
}
|
|
15
|
-
exports.Result = Result;
|
package/dist/utils/buffer.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.bufferToString = exports.timingSafeEqual = exports.equal = void 0;
|
|
4
|
-
const crypto_1 = require("./crypto");
|
|
5
|
-
const equal = (a, b) => {
|
|
1
|
+
import { sha256 } from './crypto';
|
|
2
|
+
export const equal = (a, b) => {
|
|
6
3
|
if (a === b) {
|
|
7
4
|
return true;
|
|
8
5
|
}
|
|
@@ -19,21 +16,18 @@ const equal = (a, b) => {
|
|
|
19
16
|
}
|
|
20
17
|
return true;
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
const timingSafeEqual = async (a, b, hashFunction) => {
|
|
19
|
+
export const timingSafeEqual = async (a, b, hashFunction) => {
|
|
24
20
|
if (!hashFunction) {
|
|
25
|
-
hashFunction =
|
|
21
|
+
hashFunction = sha256;
|
|
26
22
|
}
|
|
27
23
|
const sa = await hashFunction(a);
|
|
28
24
|
const sb = await hashFunction(b);
|
|
29
25
|
return sa === sb && a === b;
|
|
30
26
|
};
|
|
31
|
-
|
|
32
|
-
const bufferToString = (buffer) => {
|
|
27
|
+
export const bufferToString = (buffer) => {
|
|
33
28
|
if (buffer instanceof ArrayBuffer) {
|
|
34
29
|
const enc = new TextDecoder('utf-8');
|
|
35
30
|
return enc.decode(buffer);
|
|
36
31
|
}
|
|
37
32
|
return buffer;
|
|
38
33
|
};
|
|
39
|
-
exports.bufferToString = bufferToString;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
declare type
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
export declare type KVAssetOptions = {
|
|
3
|
+
manifest?: object | string;
|
|
4
|
+
namespace?: KVNamespace;
|
|
5
|
+
};
|
|
6
|
+
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer>;
|
|
7
|
+
declare type FilePathOptions = {
|
|
3
8
|
filename: string;
|
|
4
9
|
root?: string;
|
|
5
10
|
defaultDocument?: string;
|
|
6
11
|
};
|
|
7
|
-
export declare const getKVFilePath: (
|
|
12
|
+
export declare const getKVFilePath: (options: FilePathOptions) => string;
|
|
8
13
|
export {};
|
package/dist/utils/cloudflare.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export const getContentFromKVAsset = async (path, options) => {
|
|
2
|
+
let ASSET_MANIFEST = {};
|
|
3
|
+
if (options && options.manifest) {
|
|
4
|
+
if (typeof options.manifest === 'string') {
|
|
5
|
+
ASSET_MANIFEST = JSON.parse(options.manifest);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
ASSET_MANIFEST = options.manifest;
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
11
|
else {
|
|
10
|
-
|
|
12
|
+
if (typeof __STATIC_CONTENT_MANIFEST === 'string') {
|
|
13
|
+
ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let ASSET_NAMESPACE;
|
|
20
|
+
if (options && options.namespace) {
|
|
21
|
+
ASSET_NAMESPACE = options.namespace;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
ASSET_NAMESPACE = __STATIC_CONTENT;
|
|
11
25
|
}
|
|
12
|
-
const ASSET_NAMESPACE = __STATIC_CONTENT;
|
|
13
26
|
const key = ASSET_MANIFEST[path] || path;
|
|
14
27
|
if (!key) {
|
|
15
28
|
return;
|
|
@@ -20,11 +33,10 @@ const getContentFromKVAsset = async (path) => {
|
|
|
20
33
|
}
|
|
21
34
|
return content;
|
|
22
35
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
const defaultDocument = opt.defaultDocument || 'index.html';
|
|
36
|
+
export const getKVFilePath = (options) => {
|
|
37
|
+
let filename = options.filename;
|
|
38
|
+
let root = options.root || '';
|
|
39
|
+
const defaultDocument = options.defaultDocument || 'index.html';
|
|
28
40
|
if (filename.endsWith('/')) {
|
|
29
41
|
// /top/ => /top/index.html
|
|
30
42
|
filename = filename.concat(defaultDocument);
|
|
@@ -42,4 +54,3 @@ const getKVFilePath = (opt) => {
|
|
|
42
54
|
path = path.replace(/^\.?\//, '');
|
|
43
55
|
return path;
|
|
44
56
|
};
|
|
45
|
-
exports.getKVFilePath = getKVFilePath;
|
package/dist/utils/crypto.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHash = exports.sha1 = exports.sha256 = void 0;
|
|
4
|
-
const sha256 = async (data) => {
|
|
1
|
+
export const sha256 = async (data) => {
|
|
5
2
|
const algorithm = { name: 'SHA-256', alias: 'sha256' };
|
|
6
|
-
const hash = await
|
|
3
|
+
const hash = await createHash(data, algorithm);
|
|
7
4
|
return hash;
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
const sha1 = async (data) => {
|
|
6
|
+
export const sha1 = async (data) => {
|
|
11
7
|
const algorithm = { name: 'SHA-1', alias: 'sha1' };
|
|
12
|
-
const hash = await
|
|
8
|
+
const hash = await createHash(data, algorithm);
|
|
13
9
|
return hash;
|
|
14
10
|
};
|
|
15
|
-
|
|
16
|
-
const createHash = async (data, algorithm) => {
|
|
11
|
+
export const createHash = async (data, algorithm) => {
|
|
17
12
|
if (crypto && crypto.subtle) {
|
|
18
13
|
const buffer = await crypto.subtle.digest({
|
|
19
14
|
name: algorithm.name,
|
|
@@ -23,14 +18,4 @@ const createHash = async (data, algorithm) => {
|
|
|
23
18
|
.join('');
|
|
24
19
|
return hash;
|
|
25
20
|
}
|
|
26
|
-
try {
|
|
27
|
-
const crypto = require('crypto');
|
|
28
|
-
const hash = crypto.createHash(algorithm.alias).update(data).digest('hex');
|
|
29
|
-
return hash;
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
console.error(`If you want to create hash ${algorithm.name}, polyfill "crypto" module.`);
|
|
33
|
-
throw e;
|
|
34
|
-
}
|
|
35
21
|
};
|
|
36
|
-
exports.createHash = createHash;
|
package/dist/utils/encode.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.arrayBufferToBase64URL = exports.arrayBufferToBase64 = exports.utf8ToUint8Array = exports.decodeBase64URL = exports.encodeBase64URL = exports.decodeBase64 = exports.encodeBase64 = void 0;
|
|
27
4
|
const encodeBase64 = (str) => {
|
|
@@ -35,7 +12,6 @@ const encodeBase64 = (str) => {
|
|
|
35
12
|
}
|
|
36
13
|
catch (_a) { }
|
|
37
14
|
try {
|
|
38
|
-
const { Buffer } = require('buffer');
|
|
39
15
|
return Buffer.from(str).toString('base64');
|
|
40
16
|
}
|
|
41
17
|
catch (e) {
|
|
@@ -56,7 +32,6 @@ const decodeBase64 = (str) => {
|
|
|
56
32
|
}
|
|
57
33
|
catch (_a) { }
|
|
58
34
|
try {
|
|
59
|
-
const { Buffer } = require('buffer');
|
|
60
35
|
return Buffer.from(str, 'base64').toString();
|
|
61
36
|
}
|
|
62
37
|
catch (e) {
|
|
@@ -93,7 +68,6 @@ const arrayBufferToBase64 = async (buf) => {
|
|
|
93
68
|
return btoa(String.fromCharCode(...new Uint8Array(buf)));
|
|
94
69
|
}
|
|
95
70
|
try {
|
|
96
|
-
const { Buffer } = await Promise.resolve().then(() => __importStar(require('buffer')));
|
|
97
71
|
return Buffer.from(String.fromCharCode(...new Uint8Array(buf))).toString('base64');
|
|
98
72
|
}
|
|
99
73
|
catch (e) { }
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStatusText = void 0;
|
|
4
|
-
const getStatusText = (statusCode) => {
|
|
1
|
+
export const getStatusText = (statusCode) => {
|
|
5
2
|
const text = statuses[statusCode];
|
|
6
3
|
return text;
|
|
7
4
|
};
|
|
8
|
-
exports.getStatusText = getStatusText;
|
|
9
5
|
const statuses = {
|
|
10
6
|
100: 'Continue',
|
|
11
7
|
101: 'Switching Protocols',
|
package/dist/utils/mime.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMimeType = void 0;
|
|
4
|
-
const getMimeType = (filename) => {
|
|
1
|
+
export const getMimeType = (filename) => {
|
|
5
2
|
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
6
3
|
const match = filename.match(regexp);
|
|
7
4
|
if (!match)
|
|
@@ -12,7 +9,6 @@ const getMimeType = (filename) => {
|
|
|
12
9
|
}
|
|
13
10
|
return mimeType;
|
|
14
11
|
};
|
|
15
|
-
exports.getMimeType = getMimeType;
|
|
16
12
|
const mimes = {
|
|
17
13
|
aac: 'audio/aac',
|
|
18
14
|
abw: 'application/x-abiword',
|
package/dist/utils/url.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergePath = exports.isAbsoluteURL = exports.getPathFromURL = exports.getPattern = exports.splitPath = void 0;
|
|
4
1
|
const URL_REGEXP = /^https?:\/\/[a-zA-Z0-9\-\.:]+(\/?[^?#]*)/;
|
|
5
|
-
const splitPath = (path) => {
|
|
2
|
+
export const splitPath = (path) => {
|
|
6
3
|
const paths = path.split(/\//); // faster than path.split('/')
|
|
7
4
|
if (paths[0] === '') {
|
|
8
5
|
paths.shift();
|
|
9
6
|
}
|
|
10
7
|
return paths;
|
|
11
8
|
};
|
|
12
|
-
exports.splitPath = splitPath;
|
|
13
9
|
const patternCache = {};
|
|
14
|
-
const getPattern = (label) => {
|
|
10
|
+
export const getPattern = (label) => {
|
|
15
11
|
// * => wildcard
|
|
16
12
|
// :id{[0-9]+} => ([0-9]+)
|
|
17
13
|
// :id => (.+)
|
|
@@ -33,8 +29,7 @@ const getPattern = (label) => {
|
|
|
33
29
|
}
|
|
34
30
|
return null;
|
|
35
31
|
};
|
|
36
|
-
|
|
37
|
-
const getPathFromURL = (url, params = { strict: true }) => {
|
|
32
|
+
export const getPathFromURL = (url, params = { strict: true }) => {
|
|
38
33
|
// if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
|
|
39
34
|
// default is true
|
|
40
35
|
if (params.strict === false && url.endsWith('/')) {
|
|
@@ -46,16 +41,14 @@ const getPathFromURL = (url, params = { strict: true }) => {
|
|
|
46
41
|
}
|
|
47
42
|
return '';
|
|
48
43
|
};
|
|
49
|
-
|
|
50
|
-
const isAbsoluteURL = (url) => {
|
|
44
|
+
export const isAbsoluteURL = (url) => {
|
|
51
45
|
const match = url.match(URL_REGEXP);
|
|
52
46
|
if (match) {
|
|
53
47
|
return true;
|
|
54
48
|
}
|
|
55
49
|
return false;
|
|
56
50
|
};
|
|
57
|
-
|
|
58
|
-
const mergePath = (...paths) => {
|
|
51
|
+
export const mergePath = (...paths) => {
|
|
59
52
|
let p = '';
|
|
60
53
|
let endsWithSlash = false;
|
|
61
54
|
for (let path of paths) {
|
|
@@ -82,4 +75,3 @@ const mergePath = (...paths) => {
|
|
|
82
75
|
}
|
|
83
76
|
return p;
|
|
84
77
|
};
|
|
85
|
-
exports.mergePath = mergePath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"lint": "eslint --ext js,ts src .eslintrc.js",
|
|
13
13
|
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
|
14
|
-
"build": "rimraf dist && tsc --project tsconfig.build.json",
|
|
14
|
+
"build": "rimraf dist && tsc --project tsconfig.build.json && tsc --project tsconfig.build.esm.json",
|
|
15
15
|
"watch": "tsc --project tsconfig.build.json -w",
|
|
16
16
|
"prepublishOnly": "yarn build"
|
|
17
17
|
},
|
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
"./jwt": "./dist/middleware/jwt/index.js",
|
|
27
27
|
"./logger": "./dist/middleware/logger/index.js",
|
|
28
28
|
"./mustache": "./dist/middleware/mustache/index.js",
|
|
29
|
+
"./mustache.module": "./dist/middleware/mustache/module.mjs",
|
|
29
30
|
"./powered-by": "./dist/middleware/powered-by/index.js",
|
|
30
31
|
"./pretty-json": "./dist/middleware/pretty-json/index.js",
|
|
31
32
|
"./serve-static": "./dist/middleware/serve-static/index.js",
|
|
33
|
+
"./serve-static.module": "./dist/middleware/serve-static/module.mjs",
|
|
32
34
|
"./router/trie-router": "./dist/router/trie-router/index.js",
|
|
33
35
|
"./router/reg-exp-router": "./dist/router/reg-exp-router/index.js",
|
|
34
36
|
"./utils/jwt": "./dist/utils/jwt/index.js",
|
|
@@ -63,6 +65,9 @@
|
|
|
63
65
|
"mustache": [
|
|
64
66
|
"./dist/middleware/mustache"
|
|
65
67
|
],
|
|
68
|
+
"mustache.module": [
|
|
69
|
+
"./dist/middleware/mustache/module.d.mts"
|
|
70
|
+
],
|
|
66
71
|
"powered-by": [
|
|
67
72
|
"./dist/middleware/powered-by"
|
|
68
73
|
],
|
|
@@ -70,7 +75,10 @@
|
|
|
70
75
|
"./dist/middleware/pretty-json"
|
|
71
76
|
],
|
|
72
77
|
"serve-static": [
|
|
73
|
-
"./dist/middleware/serve-static"
|
|
78
|
+
"./dist/middleware/serve-static/index.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"serve-static.module": [
|
|
81
|
+
"./dist/middleware/serve-static/module.d.mts"
|
|
74
82
|
],
|
|
75
83
|
"router/trie-router": [
|
|
76
84
|
"./dist/router/trie-router/router.d.ts"
|