feat(entrypoint): add not found rule to customize 404 behavior

This commit is contained in:
yusing
2025-10-12 21:04:49 +08:00
parent 5640d5d454
commit dc9ae32e8f
3 changed files with 0 additions and 23 deletions

View File

@@ -196,7 +196,6 @@ func (state *state) initEntrypoint() error {
matchDomains := state.MatchDomains
state.entrypoint.SetFindRouteDomains(matchDomains)
state.entrypoint.SetCatchAllRules(epCfg.Rules.CatchAll)
state.entrypoint.SetNotFoundRules(epCfg.Rules.NotFound)
errs := gperr.NewBuilder("entrypoint error")

View File

@@ -18,7 +18,6 @@ import (
type Entrypoint struct {
middleware *middleware.Middleware
catchAllHandler http.Handler
notFoundHandler http.Handler
accessLogger *accesslog.AccessLogger
findRouteFunc func(host string) types.HTTPRoute
@@ -62,19 +61,7 @@ func (ep *Entrypoint) SetMiddlewares(mws []map[string]any) error {
return nil
}
func (ep *Entrypoint) SetCatchAllRules(rules rules.Rules) {
if len(rules) == 0 {
ep.catchAllHandler = nil
return
}
ep.catchAllHandler = rules.BuildHandler(http.HandlerFunc(ep.serveHTTP))
}
func (ep *Entrypoint) SetNotFoundRules(rules rules.Rules) {
if len(rules) == 0 {
ep.notFoundHandler = nil
return
}
ep.notFoundHandler = rules.BuildHandler(http.HandlerFunc(ep.serveNotFound))
}
@@ -97,14 +84,6 @@ func (ep *Entrypoint) FindRoute(s string) types.HTTPRoute {
}
func (ep *Entrypoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if ep.catchAllHandler != nil {
ep.catchAllHandler.ServeHTTP(w, r)
return
}
ep.serveHTTP(w, r)
}
func (ep *Entrypoint) serveHTTP(w http.ResponseWriter, r *http.Request) {
if ep.accessLogger != nil {
rec := accesslog.NewResponseRecorder(w)
w = rec

View File

@@ -8,7 +8,6 @@ import (
type Config struct {
SupportProxyProtocol bool `json:"support_proxy_protocol"`
Rules struct {
CatchAll rules.Rules `json:"catch_all"`
NotFound rules.Rules `json:"not_found"`
} `json:"rules"`
Middlewares []map[string]any `json:"middlewares"`