File size: 1,237 Bytes
6e73b5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 };