diff --git a/src/server/middlewares/setup.ts b/src/server/middlewares/setup.ts index 2a23c5a..dfdc7bc 100644 --- a/src/server/middlewares/setup.ts +++ b/src/server/middlewares/setup.ts @@ -4,23 +4,17 @@ import { cors } from "hono/cors"; import { languageDetector } from "hono/language"; import isMobile from "is-mobile"; import { JwtProvider } from "../utils/token"; +import { RedisClient } from "bun"; type AppFetch = ( input: string | Request | URL, requestInit?: RequestInit ) => Response | Promise; -type RedisClientLike = { - connect(): Promise; - get(key: string): Promise; - set(...args: unknown[]): Promise | unknown; - del(key: string): Promise | unknown; -}; - declare module "hono" { interface ContextVariableMap { fetch: AppFetch; isMobile: boolean; - redis: RedisClientLike; + redis: RedisClient; jwtProvider: JwtProvider; jwtPayload: Record; userId: string; @@ -29,7 +23,7 @@ declare module "hono" { } } -let redisClientPromise: Promise | null = null; +let redisClientPromise: Promise | null = null; const getJwtSecret = () => { const secret = (process.env.JWT_SECRET || process.env.STREAM_UI_JWT_SECRET || "").trim() || "secret_is_not_configured" @@ -47,10 +41,13 @@ const getRedisUrl = () => { return redisUrl; }; -const getRedisClient = async (): Promise => { +const getRedisClient = async (): Promise => { console.log("bun", typeof Bun) if (!redisClientPromise) { + const client = new RedisClient(getRedisUrl()) + await client.connect(); + return client; // redisClientPromise = import("Bun").then(async ({ RedisClient }) => { // const client = new RedisClient(getRedisUrl()) as RedisClientLike; // await client.connect();