Hello everyone,
i have an application on a sub-path /dashboard/page
that i want to "bypass" with an addprefix middleware. I'm in kubernetes so my middleware-configuration is like hat:
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: to-dashboard
spec:
addPrefix:
prefix: /dashboard/page
The problem with this is now that traefik always adds a trailing /
which is a problem for the application. The application always wants it without a trailing slash. So to deal with that devs of that app now are searching for trailing slashes and redirect those via 301 status to the "correct" path.
But what i get now is this:
In my browser i use http://domain/
. Traefik requests http://service/dashboard/page/
then the application redirects the browser to http://domain/dashboard/page
and traefik then tries to get http://service/dashboard/page/dashboard/page/
which has no endpoint and i only get a white page.
So how can i deal with that now? Is there any optional header or something i can add to tell treafik that it should deal with that 301 on its own instead of passing the 301 status back to the browser?
Thanks!
I assume you want to load a dashboard, which is a web GUI with various dependencies like scripts and images. It won't work like that. You always add the prefix, so dependencies like /static/script.js
can never be loaded.
Instead you could create a simple redirectRegex
only for /
to be redirected to /page/dashboard
. You would see the URL in browser, but the page can load dependencies.
# not tested
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: to-dashboard
spec:
redirectRegex:
regex: ^(https?)://([^/]+)/
replacement: ${1}://${2}/dashboard/page
hello @bluepuma77,
thanks for your answer.
Maybe you are right that it will not work but what i've done so far with addprefix always worked even with javascript stuff, websockets and so on. There was never a problem with it.
Mostly i'm using it to deploy node-red dashboards to a seperate domain to prevent users from going to the dev-ui which is not made for them.
Thanks!
So you only apply the addPrefix
to router
with .rule=Path(`/`)
?
right,
that is what I did before.
Rule match was only the host-address.
- kind: Rule
match: Host(`some.sub.server.com`)
The test with
spec:
redirectRegex:
regex: ^(https?)://([^/]+)/
replacement: ${1}://${2}/dashboard/page
was not so well. I had a loop with 5 or 6 repeated paths.
Now i used
spec:
redirectRegex:
permanent: true
regex: ^(/dashboard)?/?$
replacement: /dashboard/page
which did the job. Not so "nice" like addprefix because the path is provided to the browser url but it is ok in the environment where i use it.