liuw15 commited on
Commit
e61044b
·
1 Parent(s): 72da33d

为gemini端口加上验证

Browse files
Files changed (1) hide show
  1. src/server/index.js +9 -0
src/server/index.js CHANGED
@@ -80,6 +80,15 @@ app.use((req, res, next) => {
80
  return res.status(401).json({ error: 'Invalid API Key' });
81
  }
82
  }
 
 
 
 
 
 
 
 
 
83
  }
84
  next();
85
  });
 
80
  return res.status(401).json({ error: 'Invalid API Key' });
81
  }
82
  }
83
+ } else if (req.path.startsWith('/v1beta/')) {
84
+ const apiKey = config.security?.apiKey;
85
+ if (apiKey) {
86
+ const providedKey = req.query.key || req.headers['x-goog-api-key'];
87
+ if (providedKey !== apiKey) {
88
+ logger.warn(`API Key 验证失败: ${req.method} ${req.path} (提供的Key: ${providedKey ? providedKey.substring(0, 10) + '...' : '无'})`);
89
+ return res.status(401).json({ error: 'Invalid API Key' });
90
+ }
91
+ }
92
  }
93
  next();
94
  });