hono 0.5.1 → 0.5.2

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 CHANGED
@@ -23,12 +23,12 @@ app.fire()
23
23
 
24
24
  - **Ultrafast** - the router does not use linear loops.
25
25
  - **Zero-dependencies** - using only Web standard API.
26
- - **Middleware** - builtin middleware and your own middleware.
26
+ - **Middleware** - built-in middleware and ability to extend with your own middleware.
27
27
  - **Optimized** - for Cloudflare Workers.
28
28
 
29
29
  ## Benchmark
30
30
 
31
- **Hono is fastest** compared to other routers for Cloudflare Workers.
31
+ **Hono is fastest**, compared to other routers for Cloudflare Workers.
32
32
 
33
33
  ```plain
34
34
  hono x 809,503 ops/sec ±6.94% (73 runs sampled)
@@ -41,7 +41,7 @@ Fastest is hono
41
41
 
42
42
  ## Hono in 1 minute
43
43
 
44
- A demonstration to create an application of Cloudflare Workers with Hono.
44
+ A demonstration to create an application for Cloudflare Workers with Hono.
45
45
 
46
46
  ![Demo](https://user-images.githubusercontent.com/10682/151973526-342644f9-71c5-4fee-81f4-64a7558bb192.gif)
47
47
 
@@ -147,7 +147,7 @@ app.get('/fetch-url', async (c) => {
147
147
 
148
148
  ## Middleware
149
149
 
150
- ### Builtin Middleware
150
+ ### Built-in Middleware
151
151
 
152
152
  ```js
153
153
  import { Hono } from 'hono'
@@ -168,7 +168,7 @@ app.use(
168
168
  )
169
169
  ```
170
170
 
171
- Available builtin middleware are listed on [src/middleware](https://github.com/yusukebe/hono/tree/master/src/middleware).
171
+ Available built-in middleware is listed on [src/middleware](https://github.com/yusukebe/hono/tree/master/src/middleware).
172
172
 
173
173
  ### Custom Middleware
174
174
 
@@ -273,7 +273,7 @@ new Response('Thank you for comming', {
273
273
 
274
274
  ### c.text()
275
275
 
276
- Render texts as `Content-Type:text/plain`.
276
+ Render text as `Content-Type:text/plain`.
277
277
 
278
278
  ```js
279
279
  app.get('/say', (c) => {
@@ -381,19 +381,22 @@ export default app
381
381
 
382
382
  ## Cloudflare Workers with Hono
383
383
 
384
- Using `wrangler` or `miniflare`, you can develop the application locally and publish it with few commands.
384
+ Using [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/) or [Miniflare](https://miniflare.dev), you can develop the application locally and publish it with few commands.
385
385
 
386
386
  Let's write your first code for Cloudflare Workers with Hono.
387
387
 
388
- ### 1. Install Wrangler
388
+ ---
389
389
 
390
- Install Cloudflare Command Line "[Wrangler](https://github.com/cloudflare/wrangler)".
390
+ ### Caution
391
391
 
392
- ```sh
393
- $ npm i @cloudflare/wrangler -g
394
- ```
392
+ **Wrangler 1.x** does not support importing middleware. We recommend two ways:
393
+
394
+ 1. Use [Wragler 2.0 Beta](https://github.com/cloudflare/wrangler2).
395
+ 2. Build without webpack 4.x. For example, you can use esbuild. See [the starter template](https://github.com/yusukebe/hono-minimal).
395
396
 
396
- ### 2. `npm init`
397
+ ---
398
+
399
+ ### 1. `npm init`
397
400
 
398
401
  Make a npm skeleton directory.
399
402
 
@@ -403,15 +406,23 @@ cd hono-example
403
406
  npm init -y
404
407
  ```
405
408
 
406
- ### 3. `wrangler init`
409
+ ### 2. `wrangler init`
407
410
 
408
- Init as a wrangler project.
411
+ Initialize as a wrangler project.
409
412
 
410
- ```sh
411
- $ wrangler init
413
+ ```
414
+ $ npx wrangler@beta init
415
+ ```
416
+
417
+ Answer the questions. If you want, you can answer `y`.
418
+
419
+ ```
420
+ Would you like to install wrangler into your package.json? (y/n) <--- n
421
+ Would you like to use TypeScript? (y/n) <--- n
422
+ Would you like to create a Worker at src/index.js? (y/n) <--- n
412
423
  ```
413
424
 
414
- ### 4. `npm install hono`
425
+ ### 3. `npm install hono`
415
426
 
416
427
  Install `hono` from the npm registry.
417
428
 
@@ -419,11 +430,12 @@ Install `hono` from the npm registry.
419
430
  $ npm i hono
420
431
  ```
421
432
 
422
- ### 5. Write your app
433
+ ### 4. Write your app
423
434
 
424
435
  Only 4 lines!!
425
436
 
426
437
  ```js
438
+ // index.js
427
439
  import { Hono } from 'hono'
428
440
  const app = new Hono()
429
441
 
@@ -432,25 +444,25 @@ app.get('/', (c) => c.text('Hello! Hono!'))
432
444
  app.fire()
433
445
  ```
434
446
 
435
- ### 6. Run
447
+ ### 5. Run
436
448
 
437
449
  Run the development server locally. Then, access `http://127.0.0.1:8787/` in your Web browser.
438
450
 
439
451
  ```sh
440
- $ wrangler dev
452
+ $ npx wrangler@beta dev index.js
441
453
  ```
442
454
 
443
- ### 7. Publish
455
+ ### 6. Publish
444
456
 
445
457
  Deploy to Cloudflare. That's all!
446
458
 
447
459
  ```sh
448
- $ wrangler publish
460
+ $ npx wrangler@beta publish index.js
449
461
  ```
450
462
 
451
463
  ## Starter template
452
464
 
453
- You can start making your application of Cloudflare Workers with [the starter template](https://github.com/yusukebe/hono-minimal). It is a realy minimal using TypeScript, esbuild, and Miniflare.
465
+ You can start making your Cloudflare Workers application with [the starter template](https://github.com/yusukebe/hono-minimal). It is really minimal using TypeScript, esbuild, and Miniflare.
454
466
 
455
467
  To generate a project skelton, run this command.
456
468
 
@@ -3,6 +3,7 @@ export declare const basicAuth: (options: {
3
3
  username: string;
4
4
  password: string;
5
5
  realm?: string;
6
+ hashFunction?: Function;
6
7
  }, ...users: {
7
8
  username: string;
8
9
  password: string;
@@ -37,8 +37,8 @@ const basicAuth = (options, ...users) => {
37
37
  const requestUser = auth(ctx.req);
38
38
  if (requestUser) {
39
39
  for (const user of users) {
40
- const usernameEqual = await (0, buffer_1.timingSafeEqual)(user.username, requestUser.username);
41
- const passwordEqual = await (0, buffer_1.timingSafeEqual)(user.password, requestUser.password);
40
+ const usernameEqual = await (0, buffer_1.timingSafeEqual)(user.username, requestUser.username, options.hashFunction);
41
+ const passwordEqual = await (0, buffer_1.timingSafeEqual)(user.password, requestUser.password, options.hashFunction);
42
42
  if (usernameEqual && passwordEqual) {
43
43
  // Authorized OK
44
44
  return next();
@@ -1,2 +1,2 @@
1
1
  export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
2
- export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean) => Promise<boolean>;
2
+ export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
@@ -20,9 +20,12 @@ const equal = (a, b) => {
20
20
  return true;
21
21
  };
22
22
  exports.equal = equal;
23
- const timingSafeEqual = async (a, b) => {
24
- const sa = await (0, crypto_1.sha256)(a);
25
- const sb = await (0, crypto_1.sha256)(b);
23
+ const timingSafeEqual = async (a, b, hashFunction) => {
24
+ if (!hashFunction) {
25
+ hashFunction = crypto_1.sha256;
26
+ }
27
+ const sa = await hashFunction(a);
28
+ const sb = await hashFunction(b);
26
29
  return sa === sb && a === b;
27
30
  };
28
31
  exports.timingSafeEqual = timingSafeEqual;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "[炎] Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -78,11 +78,13 @@
78
78
  ],
79
79
  "devDependencies": {
80
80
  "@cloudflare/workers-types": "^3.3.0",
81
+ "@types/crypto-js": "^4.1.1",
81
82
  "@types/jest": "^27.4.0",
82
83
  "@types/mustache": "^4.1.2",
83
84
  "@types/node": "^17.0.8",
84
85
  "@typescript-eslint/eslint-plugin": "^5.9.0",
85
86
  "@typescript-eslint/parser": "^5.9.0",
87
+ "crypto-js": "^4.1.1",
86
88
  "eslint": "^7.26.0",
87
89
  "eslint-config-prettier": "^8.3.0",
88
90
  "eslint-define-config": "^1.2.1",