Conversation
## 问题描述 使用非 admin key 登录 Dashboard 时报错 500: ``` Error: The edge runtime does not support Node.js 'net' module. ``` ## 根本原因 - Next.js middleware 默认运行在 Edge Runtime - Edge Runtime 不支持 Node.js 的 `net` 模块 - postgres-js 驱动依赖 `net` 模块进行数据库连接 - middleware.ts 中调用 validateKey() -> 查询数据库 -> 触发错误 ## 修复内容 ### 核心修复(必须) - **src/middleware.ts**: 添加 `export const runtime = "nodejs"` 声明 ### 防御性修复(最佳实践) 为所有使用数据库的 API routes 添加显式 runtime 声明: - src/app/api/auth/login/route.ts - src/app/api/system-settings/route.ts - src/app/api/leaderboard/route.ts - src/app/api/proxy-status/route.ts - src/app/api/admin/system-config/route.ts - src/app/api/admin/database/export/route.ts - src/app/api/admin/database/import/route.ts - src/app/api/admin/database/status/route.ts - src/app/api/admin/log-cleanup/manual/route.ts - src/app/api/admin/log-level/route.ts - src/app/api/internal/data-gen/route.ts ## 为什么 API routes 之前没出问题? App Router 的 API routes 默认就是 Node.js runtime,但显式声明是最佳实践。 ## 测试 - ✅ TypeScript 类型检查通过 - ✅ 非 admin key 现在可以正常登录 Dashboard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Claude finished @ding113's task —— View job 代码审查完成 ✅
审查结果✅ 核心修复正确middleware.ts (src/middleware.ts:7) export const runtime = "nodejs";
✅ 防御性修复全面已为所有使用数据库的 API routes 添加 已覆盖的路由(11 个):
未添加但正确的路由(2 个):
✅ litellm-prices.json 更新
代码质量评估优点 👍
建议 💡
总结✅ 推荐合并 此 PR 正确修复了 Edge Runtime 兼容性问题,代码质量高,覆盖全面。所有修改都是必要且正确的:
没有发现任何代码质量问题或潜在 bug。 |
Merged
This was referenced Jan 11, 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.
问题描述
使用非 admin key 登录 Dashboard 时报错 500:
根本原因
net模块net模块进行数据库连接修复内容
核心修复(必须)
export const runtime = "nodejs"声明防御性修复(最佳实践)
为所有使用数据库的 API routes 添加显式 runtime 声明:
为什么 API routes 之前没出问题?
App Router 的 API routes 默认就是 Node.js runtime,但显式声明是最佳实践。