dan92 commited on
Commit
d48b362
·
verified ·
1 Parent(s): 9dcee15

Upload 2 files

Browse files
Files changed (1) hide show
  1. src/index.js +7 -5
src/index.js CHANGED
@@ -22,10 +22,12 @@ app.use(bodyParser({
22
  // 添加重定向中间件 - 移到路由注册之前
23
  app.use(async (ctx, next) => {
24
  console.log('收到请求:', ctx.method, ctx.path, ctx.query)
25
- const originalPath = ctx.path
26
- if (originalPath.startsWith('/v1/')) {
27
- ctx.url = '/hf' + originalPath
28
- console.log('重定向:', originalPath, '->', ctx.url)
 
 
29
  }
30
  await next()
31
  })
@@ -171,7 +173,7 @@ router.post('/v1/chat/completions', async (ctx) => {
171
 
172
  // console.log(content.delta)
173
 
174
- // 发送增量内���
175
  ctx.res.write(`data: ${JSON.stringify({
176
  "id": `chatcmpl-${messageId}`,
177
  "choices": [
 
22
  // 添加重定向中间件 - 移到路由注册之前
23
  app.use(async (ctx, next) => {
24
  console.log('收到请求:', ctx.method, ctx.path, ctx.query)
25
+ if (ctx.path.startsWith('/v1/')) {
26
+ const newPath = '/hf' + ctx.path
27
+ console.log('重定向:', ctx.path, '->', newPath)
28
+ ctx.status = 307 // 临时重定向,保持 HTTP 方法
29
+ ctx.redirect(newPath)
30
+ return
31
  }
32
  await next()
33
  })
 
173
 
174
  // console.log(content.delta)
175
 
176
+ // 发送增量内容
177
  ctx.res.write(`data: ${JSON.stringify({
178
  "id": `chatcmpl-${messageId}`,
179
  "choices": [