Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NUXT_PUBLIC_API_URL=https://kms.ikxin.com
NUXT_PUBLIC_I18N_BASE_URL=https://kms.ikxin.com
ENABLE_VLMCSD=false
NUXT_MONITOR_LIST=kms.org.cn,win.freekms.cn
NUXT_ENABLE_VLMCSD=false
NUXT_MONITOR_INTERVAL=10
25 changes: 18 additions & 7 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +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 `,` |
| `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

Expand All @@ -95,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:
Expand Down Expand Up @@ -138,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:
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ https://kms.ikxin.com

### 环境变量

| 名称 | 示例值 | 描述 |
| --------------------- | --------------------------- | ---------------------------------------- |
| `NUXT_PUBLIC_API_URL` | `https://kms.ikxin.com` | 静态版本 API 接口地址 |
| `MONITOR_LIST` | `kms.org.cn,win.freekms.cn` | 自定义监控 KMS 服务器列表,使用 `,` 分隔 |
| `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` 文件仅在开发和构建阶段有效。

### 全栈版本

Expand All @@ -95,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:
Expand Down Expand Up @@ -138,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 平台都支持静态网站托管服务,以下是通用的部署方式:
Expand Down
19 changes: 18 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// https://nuxt.com/docs/api/configuration/nuxt-config

const getMonitorCron = () => {
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} * * * * *`
}
const minutes = Math.floor(seconds / 60)
return `0 */${minutes} * * * *`
}

export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
devtools: { enabled: true },
Expand All @@ -10,7 +24,7 @@ export default defineNuxtConfig({
tasks: true,
},
scheduledTasks: {
'0/10 * * * * *': ['monitor'],
[getMonitorCron()]: ['monitor'],
},
},
app: {
Expand All @@ -25,6 +39,9 @@ export default defineNuxtConfig({
},
},
runtimeConfig: {
monitorList: '',
enableVlmcsd: '',
monitorInterval: '10',
public: {
apiUrl: '',
i18n: {
Expand Down
2 changes: 1 addition & 1 deletion server/api/monitor.ts
Original file line number Diff line number Diff line change
@@ -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<MonitorData[]>(`${host}.json`)

if (!Array.isArray(data)) {
Expand Down
8 changes: 7 additions & 1 deletion server/plugins/vlmcsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/tasks/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MonitorData[]>(`${host}.json`)

if (!Array.isArray(monitorData)) {
Expand Down
14 changes: 13 additions & 1 deletion server/utils/kms.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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,
Expand Down
Loading