fixed container routes not being loaded, added X-Forwarded-{Scheme,Proto,Host}, fixed containers with no mapping being served

This commit is contained in:
yusing
2024-09-30 18:04:47 +08:00
parent 48dd1397e8
commit 478311fe9e
8 changed files with 38 additions and 16 deletions

View File

@@ -133,6 +133,10 @@ func (r *HTTPRoute) Start() E.NestedError {
}
}
if r.entry.IsDocker() && !r.entry.ContainerRunning {
return nil
}
r.mux = http.NewServeMux()
for _, p := range r.PathPatterns {
r.mux.HandleFunc(string(p), r.handler.ServeHTTP)
@@ -160,6 +164,10 @@ func (r *HTTPRoute) Stop() E.NestedError {
return nil
}
func (r *HTTPRoute) Started() bool {
return r.mux != nil
}
func (u *URL) String() string {
return (*url.URL)(u).String()
}

View File

@@ -22,6 +22,7 @@ type (
RouteImpl interface {
Start() E.NestedError
Stop() E.NestedError
Started() bool
String() string
}
RouteType string
@@ -41,14 +42,14 @@ const (
var NewRoutes = F.NewMapOf[string, Route]
func NewRoute(en *M.RawEntry) (Route, E.NestedError) {
rt, err := P.ValidateEntry(en)
entry, err := P.ValidateEntry(en)
if err != nil {
return nil, err
}
var t RouteType
switch e := rt.(type) {
var rt RouteImpl
switch e := entry.(type) {
case *P.StreamEntry:
rt, err = NewStreamRoute(e)
t = RouteTypeStream
@@ -61,7 +62,7 @@ func NewRoute(en *M.RawEntry) (Route, E.NestedError) {
if err != nil {
return nil, err
}
return &route{RouteImpl: rt.(RouteImpl), entry: en, type_: t}, nil
return &route{RouteImpl: rt, entry: en, type_: t}, nil
}
func (rt *route) Entry() *M.RawEntry {

View File

@@ -99,6 +99,10 @@ func (r *StreamRoute) Stop() E.NestedError {
}
}
func (r *StreamRoute) Started() bool {
return r.started.Load()
}
func (r *StreamRoute) grAcceptConnections() {
defer r.wg.Done()