From b75a88b62430dff8c24aa8af52fc51c93105c1c6 Mon Sep 17 00:00:00 2001 From: yasuaki640 Date: Sun, 25 Feb 2024 19:39:58 +0900 Subject: [PATCH] Refactor middleware to use createMiddleware function --- src/middleware/basic-auth.ts | 9 +++------ src/middleware/openai.ts | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/middleware/basic-auth.ts b/src/middleware/basic-auth.ts index f082684..48a0824 100644 --- a/src/middleware/basic-auth.ts +++ b/src/middleware/basic-auth.ts @@ -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 = async ( - c, - next, -) => { +export const BasicAuthMiddleware = createMiddleware(async (c, next) => { const auth = basicAuth({ username: c.env.USERNAME, password: c.env.PASSWORD, }); return auth(c, next); -}; +}); diff --git a/src/middleware/openai.ts b/src/middleware/openai.ts index 19d2bcb..c5faf4f 100644 --- a/src/middleware/openai.ts +++ b/src/middleware/openai.ts @@ -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 = async (c, next) => { +export const OpenaiMiddleware = createMiddleware(async (c, next) => { const client = new OpenAI({ apiKey: c.env.OPENAI_API_KEY, }); c.set("openai", client); await next(); -}; +});