From 701d1b6b63a338a833d049abdfd392ec80f8b07e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 12:12:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9B=91=E6=8E=A7=E9=A2=91=E7=8E=87=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * Add MONITOR_INTERVAL env variable for customizable monitoring frequency Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> --- .env.example | 1 + README.en.md | 1 + README.md | 1 + nuxt.config.ts | 13 ++++++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 5707cb0b..c046a9f9 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ NUXT_PUBLIC_API_URL=https://kms.ikxin.com NUXT_PUBLIC_I18N_BASE_URL=https://kms.ikxin.com ENABLE_VLMCSD=false +MONITOR_INTERVAL=10 diff --git a/README.en.md b/README.en.md index 761dc514..0d364c85 100644 --- a/README.en.md +++ b/README.en.md @@ -76,6 +76,7 @@ The static version uses https://kms.ikxin.com API by default. You can deploy you | --------------------- | --------------------------- | --------------------------------------------------- | | `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | API URL for the static version | | `MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | Custom KMS server monitoring list, separated by `,` | +| `MONITOR_INTERVAL` | `10` | Monitoring interval in seconds, default is 10 | | `ENABLE_VLMCSD` | `false` | Whether to enable the built-in VLMCSD service | ### Full-Stack Version diff --git a/README.md b/README.md index 8cc38c9a..4c72e1d9 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ https://kms.ikxin.com | --------------------- | --------------------------- | ---------------------------------------- | | `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | 静态版本 API 接口地址 | | `MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | 自定义监控 KMS 服务器列表,使用 `,` 分隔 | +| `MONITOR_INTERVAL` | `10` | 监控频率,单位为秒,默认 10 秒 | | `ENABLE_VLMCSD` | `false` | 是否启用内置 VLMCSD 服务 | ### 全栈版本 diff --git a/nuxt.config.ts b/nuxt.config.ts index 62539871..66811361 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,4 +1,15 @@ // https://nuxt.com/docs/api/configuration/nuxt-config + +const getMonitorCron = () => { + const raw = parseInt(process.env.MONITOR_INTERVAL || '10', 10) + const seconds = isNaN(raw) || raw <= 0 ? 10 : raw + if (seconds < 60) { + return `*/${seconds} * * * * *` + } + const minutes = Math.floor(seconds / 60) + return `0 */${minutes} * * * *` +} + export default defineNuxtConfig({ compatibilityDate: '2024-11-01', devtools: { enabled: true }, @@ -10,7 +21,7 @@ export default defineNuxtConfig({ tasks: true, }, scheduledTasks: { - '0/10 * * * * *': ['monitor'], + [getMonitorCron()]: ['monitor'], }, }, app: { From 28ff069c7d50f0e007358adf6ff9767f2a240d18 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:10:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#37)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * fix: move MONITOR_LIST/ENABLE_VLMCSD to runtimeConfig, add PORT docs Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> * fix: resolve conflicts with main branch (merge MONITOR_INTERVAL support) Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> * fix: add MONITOR_INTERVAL to runtimeConfig as monitorInterval (NUXT_MONITOR_INTERVAL) Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com> Co-authored-by: 一纸忘忧 --- .env.example | 5 +++-- README.en.md | 26 ++++++++++++++++++-------- README.md | 26 ++++++++++++++++++-------- nuxt.config.ts | 8 +++++++- server/api/monitor.ts | 2 +- server/plugins/vlmcsd.ts | 8 +++++++- server/tasks/monitor.ts | 2 +- server/utils/kms.ts | 14 +++++++++++++- 8 files changed, 68 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index c046a9f9..abf917e7 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ NUXT_PUBLIC_API_URL=https://kms.ikxin.com NUXT_PUBLIC_I18N_BASE_URL=https://kms.ikxin.com -ENABLE_VLMCSD=false -MONITOR_INTERVAL=10 +NUXT_MONITOR_LIST=kms.org.cn,win.freekms.cn +NUXT_ENABLE_VLMCSD=false +NUXT_MONITOR_INTERVAL=10 diff --git a/README.en.md b/README.en.md index 0d364c85..33cea2d7 100644 --- a/README.en.md +++ b/README.en.md @@ -72,12 +72,16 @@ The static version uses https://kms.ikxin.com API by default. You can deploy you ### Environment Variables -| Name | Example | Description | -| --------------------- | --------------------------- | --------------------------------------------------- | -| `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | API URL for the static version | -| `MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | Custom KMS server monitoring list, separated by `,` | -| `MONITOR_INTERVAL` | `10` | Monitoring interval in seconds, default is 10 | -| `ENABLE_VLMCSD` | `false` | Whether to enable the built-in VLMCSD service | +| Name | Example | Description | +| -------------------------- | --------------------------- | ---------------------------------------------------------------------- | +| `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | API URL for the static version | +| `NUXT_MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | Custom KMS server monitoring list, separated by `,` | +| `NUXT_MONITOR_INTERVAL` | `10` | Monitoring interval in seconds, default is 10 | +| `NUXT_ENABLE_VLMCSD` | `false` | Whether to enable the built-in VLMCSD service | +| `PORT` | `3000` | Server listening port (also accepts `NITRO_PORT`) | + +> [!NOTE] +> The production server (`node .output/server/index.mjs`) does **not** automatically load `.env` files. Environment variables must be set in the system environment or your deployment platform before starting the server. The `.env` file is only used during development and the build phase. ### Full-Stack Version @@ -96,7 +100,7 @@ services: volumes: - kms-data:/app/.data environment: - - MONITOR_LIST=kms.org.cn,win.freekms.cn + - NUXT_MONITOR_LIST=kms.org.cn,win.freekms.cn restart: unless-stopped volumes: @@ -139,12 +143,18 @@ cd kms-tools && pnpm install pnpm run build ``` -3. Start the service (default port: `3000`) +3. Start the service (default port: `3000`), configurable via the `PORT` environment variable ```bash node .output/server/index.mjs ``` +To set a custom port and monitor list, pass environment variables at startup: + +```bash +PORT=3512 NUXT_MONITOR_LIST=kms.example.com node .output/server/index.mjs +``` + ### Static Version Most SaaS platforms support static website hosting. Here's the general approach: diff --git a/README.md b/README.md index 4c72e1d9..4f28280a 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,16 @@ https://kms.ikxin.com ### 环境变量 -| 名称 | 示例值 | 描述 | -| --------------------- | --------------------------- | ---------------------------------------- | -| `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | 静态版本 API 接口地址 | -| `MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | 自定义监控 KMS 服务器列表,使用 `,` 分隔 | -| `MONITOR_INTERVAL` | `10` | 监控频率,单位为秒,默认 10 秒 | -| `ENABLE_VLMCSD` | `false` | 是否启用内置 VLMCSD 服务 | +| 名称 | 示例值 | 描述 | +| -------------------------- | --------------------------- | ----------------------------------------------------------------- | +| `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | 静态版本 API 接口地址 | +| `NUXT_MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | 自定义监控 KMS 服务器列表,使用 `,` 分隔 | +| `NUXT_MONITOR_INTERVAL` | `10` | 监控频率,单位为秒,默认 10 秒 | +| `NUXT_ENABLE_VLMCSD` | `false` | 是否启用内置 VLMCSD 服务 | +| `PORT` | `3000` | 服务监听端口(也可使用 `NITRO_PORT`) | + +> [!NOTE] +> 生产环境(`node .output/server/index.mjs`)不会自动读取 `.env` 文件,环境变量需要在运行前通过系统环境或部署平台进行配置。`.env` 文件仅在开发和构建阶段有效。 ### 全栈版本 @@ -96,7 +100,7 @@ services: volumes: - kms-data:/app/.data environment: - - MONITOR_LIST=kms.org.cn,win.freekms.cn + - NUXT_MONITOR_LIST=kms.org.cn,win.freekms.cn restart: unless-stopped volumes: @@ -139,12 +143,18 @@ cd kms-tools && pnpm install pnpm run build ``` -3. 启动服务,项目默认监听 `3000` 端口 +3. 启动服务,项目默认监听 `3000` 端口,可通过 `PORT` 环境变量修改 ```bash node .output/server/index.mjs ``` +如需自定义端口和监控列表,可在启动时设置环境变量: + +```bash +PORT=3512 NUXT_MONITOR_LIST=kms.example.com node .output/server/index.mjs +``` + ### 静态版本 几乎所有 SaaS 平台都支持静态网站托管服务,以下是通用的部署方式: diff --git a/nuxt.config.ts b/nuxt.config.ts index 66811361..747a1800 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,7 +1,10 @@ // https://nuxt.com/docs/api/configuration/nuxt-config const getMonitorCron = () => { - const raw = parseInt(process.env.MONITOR_INTERVAL || '10', 10) + const raw = parseInt( + process.env.NUXT_MONITOR_INTERVAL || process.env.MONITOR_INTERVAL || '10', + 10, + ) const seconds = isNaN(raw) || raw <= 0 ? 10 : raw if (seconds < 60) { return `*/${seconds} * * * * *` @@ -36,6 +39,9 @@ export default defineNuxtConfig({ }, }, runtimeConfig: { + monitorList: '', + enableVlmcsd: '', + monitorInterval: '10', public: { apiUrl: '', i18n: { diff --git a/server/api/monitor.ts b/server/api/monitor.ts index 48fa197f..02596b2c 100644 --- a/server/api/monitor.ts +++ b/server/api/monitor.ts @@ -1,6 +1,6 @@ export default defineEventHandler(async () => { const results = await Promise.all( - monitorList.map(async host => { + getMonitorList().map(async host => { let data = await storage.getItem(`${host}.json`) if (!Array.isArray(data)) { diff --git a/server/plugins/vlmcsd.ts b/server/plugins/vlmcsd.ts index 124f73af..3d1ef11f 100644 --- a/server/plugins/vlmcsd.ts +++ b/server/plugins/vlmcsd.ts @@ -4,7 +4,13 @@ import { arch, platform } from 'os' import { existsSync } from 'fs' export default defineNitroPlugin(nitro => { - if (process.env.ENABLE_VLMCSD !== 'true') { + const config = useRuntimeConfig() + const enableVlmcsd = + config.enableVlmcsd === true || + config.enableVlmcsd === 'true' || + process.env.ENABLE_VLMCSD === 'true' + + if (!enableVlmcsd) { console.log('Vlmcsd is disabled') return } diff --git a/server/tasks/monitor.ts b/server/tasks/monitor.ts index 53a270d4..dc05ff5f 100644 --- a/server/tasks/monitor.ts +++ b/server/tasks/monitor.ts @@ -5,7 +5,7 @@ export default defineTask({ }, async run() { const results = await Promise.all( - monitorList.map(async host => { + getMonitorList().map(async host => { let monitorData = await storage.getItem(`${host}.json`) if (!Array.isArray(monitorData)) { diff --git a/server/utils/kms.ts b/server/utils/kms.ts index c67ab9bb..8ee3acdb 100644 --- a/server/utils/kms.ts +++ b/server/utils/kms.ts @@ -1,7 +1,7 @@ import { execFile } from 'child_process' import { arch, platform } from 'os' -export const monitorList = process.env.MONITOR_LIST?.split(',') || [ +const defaultMonitorList = [ 'kms.8b5.cn', 'kms.org.cn', 'win.freekms.cn', @@ -22,6 +22,18 @@ export const monitorList = process.env.MONITOR_LIST?.split(',') || [ 'kms.digiboy.ir', ] +export const getMonitorList = (() => { + let cached: string[] | undefined + return () => { + if (cached) return cached + const config = useRuntimeConfig() + const listStr = + (config.monitorList as string) || process.env.MONITOR_LIST + cached = listStr?.split(',').filter(Boolean) || defaultMonitorList + return cached + } +})() + export const runVlmcs = ({ host, port = 1688,