feat: 标准化 API 路由结构
- Claude API 路由从 /v1/* 改为 /claude/* - OpenAI API 路由从 /openai/v1/* 改为 /openai/* - 更清晰的端点命名,便于区分不同提供商 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -13,11 +13,11 @@ app.use(express.json({ limit: '50mb' }));
|
||||
// 健康检查端点
|
||||
app.get('/health', healthHandler);
|
||||
|
||||
// Claude API 代理路由: /v1/*
|
||||
app.all('/v1/*', proxyHandler);
|
||||
// Claude API 代理路由: /claude/*
|
||||
app.all('/claude/*', proxyHandler);
|
||||
|
||||
// OpenAI API 代理路由: /openai/v1/*
|
||||
app.all('/openai/v1/*', openaiProxyHandler);
|
||||
// OpenAI API 代理路由: /openai/*
|
||||
app.all('/openai/*', openaiProxyHandler);
|
||||
|
||||
// 启动服务器
|
||||
const server = app.listen(PORT, () => {
|
||||
|
||||
@@ -32,7 +32,7 @@ function extractProxyHeaders(req: Request): Record<string, string> {
|
||||
export async function openaiProxyHandler(req: Request, res: Response): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
const method = req.method;
|
||||
// 移除 /openai 前缀,保留 /v1/... 路径
|
||||
// 移除 /openai 前缀,保留完整路径(如 /v1/chat/completions)
|
||||
const requestPath = req.path.replace(/^\/openai/, '');
|
||||
const baseUrl = getOpenAIBaseUrl();
|
||||
const targetUrl = `${baseUrl}${requestPath}`;
|
||||
|
||||
@@ -32,7 +32,8 @@ function extractProxyHeaders(req: Request): Record<string, string> {
|
||||
export async function proxyHandler(req: Request, res: Response): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
const method = req.method;
|
||||
const requestPath = req.path;
|
||||
// 移除 /claude 前缀,保留完整路径(如 /v1/messages)
|
||||
const requestPath = req.path.replace(/^\/claude/, '');
|
||||
const baseUrl = getBaseUrl();
|
||||
const targetUrl = `${baseUrl}${requestPath}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user