smgc commited on
Commit
9104f63
·
verified ·
1 Parent(s): 5f466a2

Update api/index.js

Browse files
Files changed (1) hide show
  1. api/index.js +11 -6
api/index.js CHANGED
@@ -63,15 +63,19 @@ const withAuth = (request) => {
63
  const logger = (res, req) => {
64
  console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
65
  };
 
66
  const router = AutoRouter({
67
- before: [preflight, withAuth],
68
- missing: () => error(404, '404 not found.'),
69
- finally: [corsify, logger],
70
  });
71
- // Router路径
 
72
  router.get('/', () => json({ message: 'API 服务运行中~' }));
73
  router.get('/ping', () => json({ message: 'pong' }));
74
- router.get(config.API_PREFIX + '/v1/models', () =>
 
 
75
  json({
76
  object: 'list',
77
  data: [
@@ -91,7 +95,8 @@ router.get(config.API_PREFIX + '/v1/models', () =>
91
  ],
92
  })
93
  );
94
- router.post(config.API_PREFIX + '/v1/chat/completions', (req) => handleCompletion(req));
 
95
 
96
  async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
97
  // 在非GPT类型的模型中,temperature和top_p是无效的
 
63
  const logger = (res, req) => {
64
  console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
65
  };
66
+
67
  const router = AutoRouter({
68
+ before: [preflight], // 只保留 CORS preflight 检查
69
+ missing: () => error(404, '404 not found.'),
70
+ finally: [corsify, logger],
71
  });
72
+
73
+ // 不需要验证的路由
74
  router.get('/', () => json({ message: 'API 服务运行中~' }));
75
  router.get('/ping', () => json({ message: 'pong' }));
76
+
77
+ // 需要验证的路由单独添加 withAuth 中间件
78
+ router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
79
  json({
80
  object: 'list',
81
  data: [
 
95
  ],
96
  })
97
  );
98
+
99
+ router.post(config.API_PREFIX + '/v1/chat/completions', withAuth, (req) => handleCompletion(req));
100
 
101
  async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
102
  // 在非GPT类型的模型中,temperature和top_p是无效的