|
|
@@ -1,47 +1,42 @@
|
|
|
import { OpenAPIHono } from '@hono/zod-openapi'
|
|
|
-import { cors } from 'hono/cors'
|
|
|
-import { logger } from 'hono/logger'
|
|
|
import { errorHandler } from './middleware/errorHandler'
|
|
|
import { authMiddleware } from './middleware/auth.middleware'
|
|
|
import { checkPermission } from './middleware/permission.middleware'
|
|
|
import base from './api/base'
|
|
|
import { userOpenApiApp } from './api/user'
|
|
|
-import { authOpenApiApp } from './api/auth'
|
|
|
-
|
|
|
-const app = new OpenAPIHono()
|
|
|
-
|
|
|
-// Middleware chain
|
|
|
-app.use('*', logger())
|
|
|
-app.use('*', cors(
|
|
|
- // {
|
|
|
- // origin: ['http://localhost:3000'],
|
|
|
- // allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
|
- // credentials: true
|
|
|
- // }
|
|
|
-))
|
|
|
-app.use('/api/v1/*', authMiddleware)
|
|
|
-app.onError(errorHandler)
|
|
|
-
|
|
|
-// Rate limiting
|
|
|
-app.use('/api/v1/*', async (c, next) => {
|
|
|
- const ip = c.req.header('x-forwarded-for') || c.req.header('cf-connecting-ip')
|
|
|
- // 实现速率限制逻辑
|
|
|
- await next()
|
|
|
-})
|
|
|
-
|
|
|
-// Register routes
|
|
|
-app.route('/api/v1', base)
|
|
|
-app.route('/api/v1/users', userOpenApiApp)
|
|
|
-app.route('/api/v1/auth', new AuthController().routes())
|
|
|
-
|
|
|
-// OpenAPI documentation endpoint
|
|
|
-app.doc('/doc', {
|
|
|
- openapi: '3.1.0',
|
|
|
- info: {
|
|
|
- title: 'API Documentation',
|
|
|
- version: '1.0.0'
|
|
|
- },
|
|
|
- servers: [{ url: '/api/v1' }]
|
|
|
-})
|
|
|
-
|
|
|
-export default app
|
|
|
+// import { authOpenApiApp } from './api/auth'
|
|
|
+
|
|
|
+// const app = new OpenAPIHono()
|
|
|
+
|
|
|
+const createApi = (app:OpenAPIHono) => {
|
|
|
+
|
|
|
+ // app.use('/api/v1/*', authMiddleware)
|
|
|
+ app.onError(errorHandler)
|
|
|
+
|
|
|
+ // Rate limiting
|
|
|
+ app.use('/api/v1/*', async (c, next) => {
|
|
|
+ const ip = c.req.header('x-forwarded-for') || c.req.header('cf-connecting-ip')
|
|
|
+ // 实现速率限制逻辑
|
|
|
+ await next()
|
|
|
+ })
|
|
|
+
|
|
|
+ // Register routes
|
|
|
+ app.route('/api/v1', base)
|
|
|
+ app.route('/api/v1', userOpenApiApp)
|
|
|
+ // app.route('/api/v1/auth', new AuthController().routes())
|
|
|
+
|
|
|
+ // OpenAPI documentation endpoint
|
|
|
+ app.doc('/doc', {
|
|
|
+ openapi: '3.1.0',
|
|
|
+ info: {
|
|
|
+ title: 'API Documentation',
|
|
|
+ version: '1.0.0'
|
|
|
+ },
|
|
|
+ // servers: [{ url: '/api/v1' }]
|
|
|
+ })
|
|
|
+
|
|
|
+ return app;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export default createApi
|