mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01: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
|
||||
|
||||
state.entrypoint.SetFindRouteDomains(matchDomains)
|
||||
state.entrypoint.SetCatchAllRules(epCfg.Rules.CatchAll)
|
||||
state.entrypoint.SetNotFoundRules(epCfg.Rules.NotFound)
|
||||
|
||||
errs := gperr.NewBuilder("entrypoint error")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user