Fix API route middleware path for Milky#653
Merged
Merged
Conversation
Contributor
审阅者指南(在小型 PR 上折叠显示)审阅者指南调整 Milky HTTP 处理器的访问令牌中间件,使其挂载到基础的 /api 路由,而不是使用通配符路径,从而确保 API 路由能够正确匹配并执行中间件。 API 请求通过更新后的 Milky 访问令牌中间件的顺序图sequenceDiagram
actor ApiClient
participant MilkyHttpHandler
participant ExpressApp
participant AccessTokenMiddleware
participant ApiRouteHandler
ApiClient->>ExpressApp: HTTP request /prefix/api/resource
ExpressApp->>MilkyHttpHandler: Initialize with config.prefix and config.accessToken
MilkyHttpHandler->>ExpressApp: use(config.prefix + /api, AccessTokenMiddleware)
ApiClient->>ExpressApp: Request /prefix/api/resource
ExpressApp->>AccessTokenMiddleware: Invoke for /prefix/api
AccessTokenMiddleware->>AccessTokenMiddleware: Check header content-type === application/json
alt InvalidContentType
AccessTokenMiddleware-->>ApiClient: 4xx error response
else ValidContentType
AccessTokenMiddleware->>AccessTokenMiddleware: Validate access token using config.accessToken
alt TokenInvalid
AccessTokenMiddleware-->>ApiClient: 401 unauthorized
else TokenValid
AccessTokenMiddleware->>ExpressApp: next()
ExpressApp->>ApiRouteHandler: Handle /prefix/api/resource
ApiRouteHandler-->>ApiClient: 2xx success response
end
end
MilkyHttpHandler HTTP 中间件注册的类图classDiagram
class MilkyHttpHandler {
- any app
- MilkyConfig config
+ MilkyHttpHandler(app, config)
+ registerAccessTokenMiddleware()
}
class MilkyConfig {
+ string prefix
+ string accessToken
}
class ExpressApp {
+ use(path, middleware)
}
MilkyHttpHandler o-- MilkyConfig : uses
MilkyHttpHandler o-- ExpressApp : configures
MilkyHttpHandler : registerAccessTokenMiddleware()
%% Updated registration behavior
MilkyHttpHandler ..> ExpressApp : use(config.prefix + /api, middleware)
文件级变更
提示与命令与 Sourcery 交互
自定义你的使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the Milky HTTP handler’s access token middleware to attach to the base /api route instead of using a wildcard path, ensuring proper middleware matching and execution for API routes. Sequence diagram for API request passing through updated Milky access token middlewaresequenceDiagram
actor ApiClient
participant MilkyHttpHandler
participant ExpressApp
participant AccessTokenMiddleware
participant ApiRouteHandler
ApiClient->>ExpressApp: HTTP request /prefix/api/resource
ExpressApp->>MilkyHttpHandler: Initialize with config.prefix and config.accessToken
MilkyHttpHandler->>ExpressApp: use(config.prefix + /api, AccessTokenMiddleware)
ApiClient->>ExpressApp: Request /prefix/api/resource
ExpressApp->>AccessTokenMiddleware: Invoke for /prefix/api
AccessTokenMiddleware->>AccessTokenMiddleware: Check header content-type === application/json
alt InvalidContentType
AccessTokenMiddleware-->>ApiClient: 4xx error response
else ValidContentType
AccessTokenMiddleware->>AccessTokenMiddleware: Validate access token using config.accessToken
alt TokenInvalid
AccessTokenMiddleware-->>ApiClient: 401 unauthorized
else TokenValid
AccessTokenMiddleware->>ExpressApp: next()
ExpressApp->>ApiRouteHandler: Handle /prefix/api/resource
ApiRouteHandler-->>ApiClient: 2xx success response
end
end
Class diagram for MilkyHttpHandler HTTP middleware registrationclassDiagram
class MilkyHttpHandler {
- any app
- MilkyConfig config
+ MilkyHttpHandler(app, config)
+ registerAccessTokenMiddleware()
}
class MilkyConfig {
+ string prefix
+ string accessToken
}
class ExpressApp {
+ use(path, middleware)
}
MilkyHttpHandler o-- MilkyConfig : uses
MilkyHttpHandler o-- ExpressApp : configures
MilkyHttpHandler : registerAccessTokenMiddleware()
%% Updated registration behavior
MilkyHttpHandler ..> ExpressApp : use(config.prefix + /api, middleware)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
你好——我已经审查了你的修改,看起来非常棒!
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的代码审查。
Original comment in English
Hey there - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary by Sourcery
Bug Fixes:
Original summary in English
Summary by Sourcery
Bug Fixes: