Skip to content

Commit f240e7e

Browse files
committed
fix: final version of the path fix
1 parent b33743d commit f240e7e

4 files changed

Lines changed: 50 additions & 28 deletions

File tree

containers/aggregator-server/main.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,31 @@ func main() {
169169
})
170170

171171
// Start HTTP server
172+
handler := http.Handler(serverMux)
173+
if basePath := strings.TrimSuffix(model.ExternalBasePath, "/"); basePath != "" {
174+
// Accept requests both with and without the configured external base path.
175+
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
176+
path := r.URL.Path
177+
if path == basePath || strings.HasPrefix(path, basePath+"/") {
178+
rewrittenPath := strings.TrimPrefix(path, basePath)
179+
if rewrittenPath == "" {
180+
rewrittenPath = "/"
181+
}
182+
clone := r.Clone(r.Context())
183+
urlCopy := *r.URL
184+
urlCopy.Path = rewrittenPath
185+
urlCopy.RawPath = ""
186+
clone.URL = &urlCopy
187+
serverMux.ServeHTTP(w, clone)
188+
return
189+
}
190+
serverMux.ServeHTTP(w, r)
191+
})
192+
}
193+
172194
srv := &http.Server{
173195
Addr: ":5000",
174-
Handler: serverMux,
196+
Handler: handler,
175197
}
176198

177199
go func() {

containers/aggregator-server/registration/namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func deployAggregatorResources(namespace string, tokenEndpoint string, accessTok
315315
"namespace": namespace,
316316
},
317317
"spec": map[string]interface{}{
318-
"entryPoints": []string{"web"},
318+
"entryPoints": []string{"web", "websecure"},
319319
"routes": []interface{}{
320320
map[string]interface{}{
321321
"match": "Host(`" + hostMatch + "`) && " + exactPathRule(configBasePaths) + " && Method(`OPTIONS`)",

containers/aggregator/services/create-service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func createIngressRoute(service *model.Service, owner model.User, ctx context.Co
399399
"namespace": namespace,
400400
},
401401
"spec": map[string]interface{}{
402-
"entryPoints": []string{"web"},
402+
"entryPoints": []string{"web", "websecure"},
403403
"routes": []interface{}{
404404
map[string]interface{}{
405405
"match": "Host(`" + hostMatch + "`) && " + servicePrefixRule(servicePathPrefixes) + " && Method(`OPTIONS`)",

k8s/app/aggregator.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,27 @@ spec:
175175
- port: 5000
176176
targetPort: 5000
177177
---
178-
# =======================
179-
# 6 Ingress
180-
# ========================
181-
apiVersion: traefik.io/v1alpha1
182-
kind: IngressRoute
183-
metadata:
184-
name: aggregator-server-ingressroute
178+
# =======================
179+
# 6 Ingress
180+
# ========================
181+
apiVersion: traefik.io/v1alpha1
182+
kind: IngressRoute
183+
metadata:
184+
name: aggregator-server-ingressroute
185185
namespace: aggregator-app
186186
spec:
187187
entryPoints:
188188
- web
189189
routes:
190-
- match: Host(`aggregator.local`) && PathPrefix(`/`)
191-
kind: Rule
192-
middlewares:
193-
- name: cors
194-
namespace: aggregator-app
195-
services:
196-
- name: aggregator-server-svc
197-
port: 5000
198-
---
190+
- match: Host(`aggregator.local`) && PathPrefix(`/`)
191+
kind: Rule
192+
middlewares:
193+
- name: cors
194+
namespace: aggregator-app
195+
services:
196+
- name: aggregator-server-svc
197+
port: 5000
198+
---
199199
apiVersion: traefik.io/v1alpha1
200200
kind: IngressRoute
201201
metadata:
@@ -205,12 +205,12 @@ spec:
205205
entryPoints:
206206
- web
207207
routes:
208-
- match: Host(`aggregator.local`) && PathPrefix(`/registration`)
209-
kind: Rule
210-
middlewares:
211-
- name: cors
212-
namespace: aggregator-app
213-
services:
214-
- name: aggregator-server-svc
215-
port: 5000
216-
---
208+
- match: Host(`aggregator.local`) && PathPrefix(`/registration`)
209+
kind: Rule
210+
middlewares:
211+
- name: cors
212+
namespace: aggregator-app
213+
services:
214+
- name: aggregator-server-svc
215+
port: 5000
216+
---

0 commit comments

Comments
 (0)