hono 1.2.0 → 1.2.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/README.md CHANGED
@@ -546,7 +546,7 @@ npx wrangler dev
546
546
  Deploy to Cloudflare. That's all!
547
547
 
548
548
  ```
549
- npx wrangler publish index.ts
549
+ npx wrangler publish ./src/index.ts
550
550
  ```
551
551
 
552
552
  ## Starter template
package/dist/context.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class Context<RequestParamKeyType = string, E = Env> {
13
13
  private _statusText;
14
14
  private _pretty;
15
15
  private _prettySpace;
16
+ private _map;
16
17
  render: (template: string, params?: object, options?: object) => Promise<Response>;
17
18
  notFound: () => Response | Promise<Response>;
18
19
  constructor(req: Request<RequestParamKeyType>, opts?: {
@@ -23,6 +24,8 @@ export declare class Context<RequestParamKeyType = string, E = Env> {
23
24
  private initRequest;
24
25
  header(name: string, value: string): void;
25
26
  status(status: StatusCode): void;
27
+ set(key: string, value: any): void;
28
+ get(key: string): any;
26
29
  pretty(prettyJSON: boolean, space?: number): void;
27
30
  newResponse(data: Data, init?: ResponseInit): Response;
28
31
  body(data: Data, status?: StatusCode, headers?: Headers): Response;
package/dist/context.js CHANGED
@@ -12,6 +12,7 @@ class Context {
12
12
  this._pretty = false;
13
13
  this._prettySpace = 2;
14
14
  this.req = this.initRequest(req);
15
+ this._map = {};
15
16
  Object.assign(this, opts);
16
17
  }
17
18
  initRequest(req) {
@@ -34,6 +35,12 @@ class Context {
34
35
  this._status = status;
35
36
  this._statusText = (0, http_status_1.getStatusText)(status);
36
37
  }
38
+ set(key, value) {
39
+ this._map[key] = value;
40
+ }
41
+ get(key) {
42
+ return this._map[key];
43
+ }
37
44
  pretty(prettyJSON, space = 2) {
38
45
  this._pretty = prettyJSON;
39
46
  this._prettySpace = space;
@@ -42,17 +42,16 @@ const basicAuth = (options, ...users) => {
42
42
  if (usernameEqual && passwordEqual) {
43
43
  // Authorized OK
44
44
  await next();
45
+ return;
45
46
  }
46
47
  }
47
48
  }
48
- else {
49
- ctx.res = new Response('Unauthorized', {
50
- status: 401,
51
- headers: {
52
- 'WWW-Authenticate': 'Basic realm="' + options.realm.replace(/"/g, '\\"') + '"',
53
- },
54
- });
55
- }
49
+ ctx.res = new Response('Unauthorized', {
50
+ status: 401,
51
+ headers: {
52
+ 'WWW-Authenticate': 'Basic realm="' + options.realm.replace(/"/g, '\\"') + '"',
53
+ },
54
+ });
56
55
  };
57
56
  };
58
57
  exports.basicAuth = basicAuth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",