-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor middleware to use createMiddleware function
- Loading branch information
1 parent
e789c07
commit b75a88b
Showing
2 changed files
with
6 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import { MiddlewareHandler } from "hono"; | ||
import { basicAuth } from "hono/basic-auth"; | ||
import { createMiddleware } from "hono/factory"; | ||
|
||
import { AppEnv } from "../types"; | ||
|
||
export const BasicAuthMiddleware: MiddlewareHandler<AppEnv> = async ( | ||
c, | ||
next, | ||
) => { | ||
export const BasicAuthMiddleware = createMiddleware<AppEnv>(async (c, next) => { | ||
const auth = basicAuth({ | ||
username: c.env.USERNAME, | ||
password: c.env.PASSWORD, | ||
}); | ||
return auth(c, next); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { MiddlewareHandler } from "hono"; | ||
import { createMiddleware } from "hono/factory"; | ||
import OpenAI from "openai"; | ||
|
||
import { AppEnv } from "../types"; | ||
|
||
export const OpenaiMiddleware: MiddlewareHandler<AppEnv> = async (c, next) => { | ||
export const OpenaiMiddleware = createMiddleware<AppEnv>(async (c, next) => { | ||
const client = new OpenAI({ | ||
apiKey: c.env.OPENAI_API_KEY, | ||
}); | ||
c.set("openai", client); | ||
await next(); | ||
}; | ||
}); |