JWT router add basePath support#2996
Open
aresnasa wants to merge 4 commits intoccfos:mainfrom
Open
Conversation
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.
Nightingale BaseURL/BasePath 功能分析文档
概述
Nightingale v6 已支持通过
BasePath配置进行反向代理部署,允许在非根路径上运行应用。本文档记录了完整的实现细节,用于向 nightingale 社区提交改进 PR。核心实现
1. 配置定义 (
pkg/httpx/httpx.go)功能:允许在配置文件中指定应用的基础路径前缀。
2. 路径规范化函数 (
pkg/httpx/httpx.go)功能:
/开头/结尾(移除末尾斜杠)示例:
"/nightingale"→/nightingale"nightingale"→/nightingale"/nightingale/"→/nightingale""→""3. Gin 引擎初始化 (
pkg/httpx/httpx.go)覆盖的路由:
{basePath}/ping- 健康检查{basePath}/pid- 获取进程 ID{basePath}/ppid- 获取父进程 ID{basePath}/addr- 获取远程地址{basePath}/api/n9e/version- 获取版本信息{basePath}/metrics- Prometheus 指标(可选){basePath}/api/debug/pprof- 性能分析(可选)4. 中心路由配置 (
center/router/router.go)4.1 静态文件服务
4.2 API 路由前缀
4.3 前端路由处理 (
configNoRoute)关键点:
5. Alert 路由配置 (
alert/router/router.go)6. Pushgw 路由配置 (
pushgw/router/router.go)配置示例
YAML 配置
使用场景
Nginx 反向代理
此时配置
basePath: "/monitoring"子域名反向代理
容器编排平台
改进建议(PR 建议)
1. 前端 BaseURL 传递机制
当前状态:后端支持 basePath,但前端可能需要知道该值以正确构建 API 请求。
建议:
前端可以从该端点获取 basePath,然后用于构建所有 API 请求。
2. 文档改进
3. 中间件支持
可以创建一个中间件来自动处理 basePath:
4. 测试覆盖
需要添加测试用例来验证:
相关文件总结
pkg/httpx/httpx.gocenter/router/router.goalert/router/router.gopushgw/router/router.go总结
Nightingale v6 已经具有完整的 basePath 支持,主要包括:
提交 PR 的要点
生成时间:2025-12-15
用途:向 nightingale 社区提交 PR 的参考文档