fenghuo/apps/backend/src/index.ts

51 lines
1.1 KiB
TypeScript

import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { contextStorage, getContext } from 'hono/context-storage'
import { prettyJSON } from 'hono/pretty-json'
import { trpcServer } from '@hono/trpc-server'
import { appRouter } from './trpc'
import Redis from 'ioredis'
import redis from './redis'
import minioClient from './minio'
import { Client } from 'minio'
import oidc from './oidc/provider'
type Env = {
Variables: {
redis: Redis
minio: Client
}
}
const app = new Hono<Env>()
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.get('/', (c) => {
return c.text('Hello Hono!')
})
app.all('/oidc/*', async (c) => {
// 让 oidc-provider 处理请求
return await oidc.callback(c.req.raw, c.res.raw);
});
export default app