hono 0.3.0 → 0.3.1
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/compose.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.compose = void 0;
|
|
4
4
|
// Based on the code in the MIT licensed `koa-compose` package.
|
|
5
5
|
const compose = (middleware) => {
|
|
6
|
+
const errors = [];
|
|
6
7
|
return function (context, next) {
|
|
7
8
|
let index = -1;
|
|
8
9
|
return dispatch(0);
|
|
@@ -16,7 +17,10 @@ const compose = (middleware) => {
|
|
|
16
17
|
if (!fn)
|
|
17
18
|
return Promise.resolve();
|
|
18
19
|
try {
|
|
19
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))
|
|
20
|
+
return Promise.resolve(fn(context, dispatch.bind(null, i + 1))).catch((e) => {
|
|
21
|
+
errors.push(e);
|
|
22
|
+
throw errors[0]; // XXX
|
|
23
|
+
});
|
|
20
24
|
}
|
|
21
25
|
catch (err) {
|
|
22
26
|
return Promise.reject(err);
|
|
@@ -25,7 +25,13 @@ const auth = (req) => {
|
|
|
25
25
|
return { username: userPass[1], password: userPass[2] };
|
|
26
26
|
};
|
|
27
27
|
function decodeBase64(str) {
|
|
28
|
-
|
|
28
|
+
if (atob && btoa) {
|
|
29
|
+
return atob(str);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const { Buffer } = require('buffer');
|
|
33
|
+
return Buffer.from(str, 'base64').toString();
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
const basicAuth = (options) => {
|
|
31
37
|
if (!options.realm) {
|
|
@@ -33,8 +39,8 @@ const basicAuth = (options) => {
|
|
|
33
39
|
}
|
|
34
40
|
return async (ctx, next) => {
|
|
35
41
|
const user = auth(ctx.req);
|
|
36
|
-
const usernameEqual = user && await (0, buffer_1.timingSafeEqual)(options.username, user.username);
|
|
37
|
-
const passwordEqual = user && await (0, buffer_1.timingSafeEqual)(options.password, user.password);
|
|
42
|
+
const usernameEqual = user && (await (0, buffer_1.timingSafeEqual)(options.username, user.username));
|
|
43
|
+
const passwordEqual = user && (await (0, buffer_1.timingSafeEqual)(options.password, user.password));
|
|
38
44
|
if (!user || !usernameEqual || !passwordEqual) {
|
|
39
45
|
ctx.res = new Response('Unauthorized', {
|
|
40
46
|
status: 401,
|
|
@@ -4,16 +4,13 @@ exports.mustache = void 0;
|
|
|
4
4
|
const cloudflare_1 = require("../../utils/cloudflare");
|
|
5
5
|
const EXTENSION = '.mustache';
|
|
6
6
|
const mustache = () => {
|
|
7
|
-
let Mustache;
|
|
8
|
-
try {
|
|
9
|
-
Mustache = require('mustache');
|
|
10
|
-
}
|
|
11
|
-
catch (_a) {
|
|
12
|
-
// Do nothing.
|
|
13
|
-
}
|
|
14
7
|
return async (c, next) => {
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
let Mustache;
|
|
9
|
+
try {
|
|
10
|
+
Mustache = require('mustache');
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
throw new Error('If you want to use Mustache Middleware, install "mustache" package first.');
|
|
17
14
|
}
|
|
18
15
|
c.render = async (filename, view = {}, options) => {
|
|
19
16
|
const buffer = await (0, cloudflare_1.getContentFromKVAsset)(`${filename}${EXTENSION}`);
|