Skip to content

Commit 524c089

Browse files
committed
Allow Hono middleware config param to be typed and to be async
1 parent b856fae commit 524c089

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
- Allow Hono middleware config param to be typed
11+
- Allow Hono middleware config param to be async
12+
1013
## [4.0.0] - 2025-10-01
1114

1215
- BREAKING: Restructure hono middleware for lazy config

src/hono/ServeGrip.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type HonoRequest, type Context, type MiddlewareHandler } from 'hono';
1+
import { type Env as HonoEnv, type HonoRequest, type Context, type MiddlewareHandler } from 'hono';
22
import { createMiddleware } from 'hono/factory'
33
import {
44
type WebSocketContext,
@@ -87,18 +87,18 @@ class ServeGrip extends ServeGripBase<RequestState, ResponseState> {
8787
}
8888
}
8989

90-
export type ServeGripParams =
91-
| IServeGripConfig
92-
| ((c: Context) => IServeGripConfig)
90+
export type ServeGripParams<E extends HonoEnv> =
91+
| (Promise<IServeGripConfig> | IServeGripConfig)
92+
| ((c: Context<E>) => (Promise<IServeGripConfig> | IServeGripConfig))
9393
;
9494

95-
export function serveGrip(config: ServeGripParams): MiddlewareHandler<Env> {
95+
export function serveGrip<E extends Env>(config: ServeGripParams<E>): MiddlewareHandler<E> {
9696

9797
const configBuilder = typeof config === 'function' ? config : () => config;
9898

99-
return createMiddleware<Env>(async (c, next) => {
99+
return createMiddleware<E>(async (c, next) => {
100100

101-
const configValue = configBuilder(c);
101+
const configValue = await configBuilder(c);
102102
const serveGripInstance = new ServeGrip(configValue);
103103

104104
const requestState: RequestState = {

0 commit comments

Comments
 (0)