Spaces:
Paused
Paused
| import 'dotenv/config'; | |
| import { H3, serve } from "h3"; | |
| import { authMiddleware } from './middleware/auth.js'; | |
| import { corsMiddleware } from './middleware/cors.js'; | |
| import { chatCompletions, listModels, getModel } from './routes/openai.js'; | |
| const app = new H3(); | |
| // 中间件 | |
| app.use(corsMiddleware); | |
| app.use(authMiddleware); | |
| // 健康检查 | |
| app.get('/health', () => { | |
| return { | |
| status: 'ok', | |
| timestamp: new Date().toISOString(), | |
| version: '1.0.0', | |
| workspace_id: process.env.WORKSPACE_ID ? 'configured' : 'not_configured' | |
| }; | |
| }); | |
| // OpenAI 兼容接口 | |
| app.post('/v1/chat/completions', chatCompletions); | |
| app.get('/v1/models', listModels); | |
| app.get('/v1/models/:model', getModel); | |
| // API 信息接口 | |
| app.get('/v1', () => { | |
| return { | |
| message: 'Dust to OpenAI API Bridge', | |
| version: '1.0.0', | |
| endpoints: { | |
| chat: '/v1/chat/completions', | |
| models: '/v1/models', | |
| health: '/health', | |
| } | |
| }; | |
| }); | |
| // 启动服务器 | |
| const port = process.env.PORT || 7860; | |
| serve(app, { port }); | |
| console.log(`🚀 Server running on port ${port}`); | |
| console.log(`📖 Health check: http://localhost:${port}/health`); | |
| console.log(`🤖 OpenAI API: http://localhost:${port}/v1/chat/completions`); | |
| export { app }; | |