fix: 将环境变量迁移到 runtimeConfig,修复生产环境环境变量不生效问题#37
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for kms-tools ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix API URL and port configuration issues
fix: 将 MONITOR_LIST/ENABLE_VLMCSD 迁移到 runtimeConfig,修复生产环境环境变量不生效问题
Mar 18, 2026
Owner
|
@copilot 解决最新代码的冲突 |
Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com>
Contributor
Author
Owner
Contributor
Author
Owner
|
@copilot MONITOR_INTERVAL 也需要在 Nuxt 运行时读取呀 |
…ONITOR_INTERVAL) Co-authored-by: ikxin <54543761+ikxin@users.noreply.github.com>
Contributor
Author
已在 f31ae34 中处理:
注意:scheduled task 的 cron 表达式在构建时确定,修改 |
Copilot
AI
changed the title
fix: 将 MONITOR_LIST/ENABLE_VLMCSD 迁移到 runtimeConfig,修复生产环境环境变量不生效问题
fix: 将 MONITOR_LIST/ENABLE_VLMCSD/MONITOR_INTERVAL 迁移到 runtimeConfig,修复生产环境环境变量不生效问题
Mar 18, 2026
ikxin
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
生产服务器(
node .output/server/index.mjs)不会自动加载.env文件,且MONITOR_LIST/ENABLE_VLMCSD/MONITOR_INTERVAL未注册到 NuxtruntimeConfig,导致这些变量在生产环境始终无法生效。此外,-p端口参数对 Nitro 无效,需通过PORT环境变量修改。这个变动的性质是
需求背景
生产部署(宝塔面板等)中设置
.env后重新构建,MONITOR_LIST监控列表和 API 地址仍不生效。根本原因:.env,环境变量必须在启动进程前注入系统环境MONITOR_LIST/ENABLE_VLMCSD/MONITOR_INTERVAL直接读取process.env,未进入 Nuxt 的runtimeConfig体系,无法通过applyEnv()在服务启动时正确应用实现方案和 API(非新功能可选)
核心修复: 将
MONITOR_LIST/ENABLE_VLMCSD/MONITOR_INTERVAL全部注册进runtimeConfig,使 Nitro 的applyEnv()在服务启动时自动将NUXT_*前缀环境变量注入配置。nuxt.config.ts:runtimeConfig新增monitorList: ''、enableVlmcsd: ''和monitorInterval: '10',触发NUXT_MONITOR_LIST/NUXT_ENABLE_VLMCSD/NUXT_MONITOR_INTERVAL的自动映射;getMonitorCron()函数优先读取NUXT_MONITOR_INTERVAL,回退MONITOR_INTERVAL(向后兼容)server/utils/kms.ts:monitorList常量改为带缓存的getMonitorList()函数,优先读取useRuntimeConfig().monitorList,回退process.env.MONITOR_LIST(向后兼容)server/plugins/vlmcsd.ts:改用useRuntimeConfig().enableVlmcsd,回退process.env.ENABLE_VLMCSDserver/api/monitor.ts、server/tasks/monitor.ts:改用getMonitorList()启动命令示例(端口修改同样适用):
Note
MONITOR_INTERVAL(NUXT_MONITOR_INTERVAL)用于控制 scheduled task 的 cron 表达式,该值在构建时确定并编译进产物,修改后需重新 build 生效。文档:
.env.example更新为NUXT_MONITOR_LIST/NUXT_ENABLE_VLMCSD/NUXT_MONITOR_INTERVALREADME.md/README.en.md更新变量名表格,新增PORT、NUXT_MONITOR_INTERVAL说明,新增生产环境不加载.env的注意事项对用户的影响和可能的风险(非新功能可选)
MONITOR_LIST→NUXT_MONITOR_LIST,ENABLE_VLMCSD→NUXT_ENABLE_VLMCSD,MONITOR_INTERVAL→NUXT_MONITOR_INTERVAL。旧名称仍作为 fallback 保留,不强制迁移,向后兼容MONITOR_LIST同步更新为NUXT_MONITOR_LISTChangelog 描述(非新功能可选)
MONITOR_LIST,ENABLE_VLMCSD, andMONITOR_INTERVALnow properly registered in NuxtruntimeConfig; useNUXT_MONITOR_LIST/NUXT_ENABLE_VLMCSD/NUXT_MONITOR_INTERVALin production. Old names remain as fallback. AddedPORTandNUXT_MONITOR_INTERVALenv var documentation.MONITOR_LIST、ENABLE_VLMCSD和MONITOR_INTERVAL已迁移至 NuxtruntimeConfig,生产环境请使用NUXT_MONITOR_LIST/NUXT_ENABLE_VLMCSD/NUXT_MONITOR_INTERVAL,旧变量名作为回退仍可用。新增PORT和NUXT_MONITOR_INTERVAL环境变量文档说明。请求合并前的自查清单
后续计划(非新功能可选)
无。
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.