import { Hono } from 'hono' import { logger } from 'hono/logger' import { contextStorage, getContext } from 'hono/context-storage' import { prettyJSON } from 'hono/pretty-json' import { cors } from 'hono/cors' import { trpcServer } from '@hono/trpc-server' import Redis from 'ioredis' import redis from './redis' import minioClient from './minio' import { Client } from 'minio' import oidc from './oidc/provider' import { appRouter } from './trpc' type Env = { Variables: { redis: Redis; minio: Client; }; }; const app = new Hono(); app.use('*', cors({ origin: 'http://localhost:3001', credentials: true, })) app.use('*', async (c, next) => { c.set('redis', redis); c.set('minio', minioClient); await next(); }); app.use('*', async (c, next) => { c.set('redis', redis); await next(); }); app.use(contextStorage()); app.use(prettyJSON()); // With options: prettyJSON({ space: 4 }) app.use(logger()); app.use( '/trpc/*', trpcServer({ router: appRouter, }), ); app.use('/oidc/*', async (c, next) => { // @ts-ignore await oidc.callback(c.req.raw, c.res.raw); // return void 也可以 return; }); export default app;