From be9341af7cb13fc2f4b1597ed60fc060983ee43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= <7836246@qq.com> Date: Tue, 10 Mar 2026 15:16:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BB=8E=20package.json=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=EF=BC=8C=E5=8E=BB=E9=99=A4=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0efa2f7..0160ebb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,11 +6,17 @@ */ import 'dotenv/config'; +import { createRequire } from 'module'; import express from 'express'; import { getConfig } from './config.js'; import { handleMessages, listModels, countTokens } from './handler.js'; import { handleOpenAIChatCompletions } from './openai-handler.js'; +// 从 package.json 读取版本号,统一来源,避免多处硬编码 +const require = createRequire(import.meta.url); +const { version: VERSION } = require('../package.json') as { version: string }; + + const app = express(); const config = getConfig(); @@ -48,14 +54,14 @@ app.get('/v1/models', listModels); // 健康检查 app.get('/health', (_req, res) => { - res.json({ status: 'ok', version: '2.4.0' }); + res.json({ status: 'ok', version: VERSION }); }); // 根路径 app.get('/', (_req, res) => { res.json({ name: 'cursor2api', - version: '2.4.0', + version: VERSION, description: 'Cursor Docs AI → Anthropic & OpenAI API Proxy', endpoints: { anthropic_messages: 'POST /v1/messages', @@ -75,7 +81,7 @@ app.get('/', (_req, res) => { app.listen(config.port, () => { console.log(''); console.log(' ╔══════════════════════════════════════╗'); - console.log(' ║ Cursor2API v2.4.0 ║'); + console.log(` ║ Cursor2API v${VERSION.padEnd(21)}║`); console.log(' ╠══════════════════════════════════════╣'); console.log(` ║ Server: http://localhost:${config.port} ║`); console.log(' ║ Model: ' + config.cursorModel.padEnd(26) + '║');