refactor(api): 将健康检查和令牌计数处理逻辑移至请求处理器
重构代码结构,将原本在api-manager.js中的健康检查端点和令牌计数请求处理
This commit is contained in:
parent
0149bf6558
commit
1dde8b5a74
2 changed files with 22 additions and 20 deletions
|
|
@ -18,27 +18,7 @@ import {
|
||||||
* @returns {Promise<boolean>} - True if the request was handled by API
|
* @returns {Promise<boolean>} - True if the request was handled by API
|
||||||
*/
|
*/
|
||||||
export async function handleAPIRequests(method, path, req, res, currentConfig, apiService, providerPoolManager, promptLogFilename) {
|
export async function handleAPIRequests(method, path, req, res, currentConfig, apiService, providerPoolManager, promptLogFilename) {
|
||||||
// Health check endpoint
|
|
||||||
if (method === 'GET' && path === '/health') {
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
status: 'healthy',
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
provider: currentConfig.MODEL_PROVIDER
|
|
||||||
}));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore count_tokens requests
|
|
||||||
if (path.includes('/count_tokens')) {
|
|
||||||
console.log(`[Server] Ignoring count_tokens request: ${path}`);
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
tokens: 0,
|
|
||||||
message: 'Token counting is not supported'
|
|
||||||
}));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Route model list requests
|
// Route model list requests
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,28 @@ export function createRequestHandler(config, providerPoolManager) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Health check endpoint
|
||||||
|
if (method === 'GET' && path === '/health') {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
status: 'healthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
provider: currentConfig.MODEL_PROVIDER
|
||||||
|
}));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore count_tokens requests
|
||||||
|
if (path.includes('/count_tokens')) {
|
||||||
|
console.log(`[Server] Ignoring count_tokens request: ${path}`);
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
tokens: 0,
|
||||||
|
message: 'Token counting is not supported'
|
||||||
|
}));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check authentication for API requests
|
// Check authentication for API requests
|
||||||
if (!isAuthorized(req, requestUrl, currentConfig.REQUIRED_API_KEY)) {
|
if (!isAuthorized(req, requestUrl, currentConfig.REQUIRED_API_KEY)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue