mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02:00
feat(entrypoint): add not found rule to customize 404 behavior
This commit is contained in:
@@ -196,7 +196,6 @@ func (state *state) initEntrypoint() error {
|
|||||||
matchDomains := state.MatchDomains
|
matchDomains := state.MatchDomains
|
||||||
|
|
||||||
state.entrypoint.SetFindRouteDomains(matchDomains)
|
state.entrypoint.SetFindRouteDomains(matchDomains)
|
||||||
state.entrypoint.SetCatchAllRules(epCfg.Rules.CatchAll)
|
|
||||||
state.entrypoint.SetNotFoundRules(epCfg.Rules.NotFound)
|
state.entrypoint.SetNotFoundRules(epCfg.Rules.NotFound)
|
||||||
|
|
||||||
errs := gperr.NewBuilder("entrypoint error")
|
errs := gperr.NewBuilder("entrypoint error")
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import (
|
|||||||
|
|
||||||
type Entrypoint struct {
|
type Entrypoint struct {
|
||||||
middleware *middleware.Middleware
|
middleware *middleware.Middleware
|
||||||
catchAllHandler http.Handler
|
|
||||||
notFoundHandler http.Handler
|
notFoundHandler http.Handler
|
||||||
accessLogger *accesslog.AccessLogger
|
accessLogger *accesslog.AccessLogger
|
||||||
findRouteFunc func(host string) types.HTTPRoute
|
findRouteFunc func(host string) types.HTTPRoute
|
||||||
@@ -62,19 +61,7 @@ func (ep *Entrypoint) SetMiddlewares(mws []map[string]any) error {
|
|||||||
return nil
|
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) {
|
func (ep *Entrypoint) SetNotFoundRules(rules rules.Rules) {
|
||||||
if len(rules) == 0 {
|
|
||||||
ep.notFoundHandler = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ep.notFoundHandler = rules.BuildHandler(http.HandlerFunc(ep.serveNotFound))
|
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) {
|
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 {
|
if ep.accessLogger != nil {
|
||||||
rec := accesslog.NewResponseRecorder(w)
|
rec := accesslog.NewResponseRecorder(w)
|
||||||
w = rec
|
w = rec
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
SupportProxyProtocol bool `json:"support_proxy_protocol"`
|
SupportProxyProtocol bool `json:"support_proxy_protocol"`
|
||||||
Rules struct {
|
Rules struct {
|
||||||
CatchAll rules.Rules `json:"catch_all"`
|
|
||||||
NotFound rules.Rules `json:"not_found"`
|
NotFound rules.Rules `json:"not_found"`
|
||||||
} `json:"rules"`
|
} `json:"rules"`
|
||||||
Middlewares []map[string]any `json:"middlewares"`
|
Middlewares []map[string]any `json:"middlewares"`
|
||||||
|
|||||||
Reference in New Issue
Block a user