server: templates: use relative URLs to refer to assets#1554
Conversation
97b0a2d to
e67635c
Compare
|
Hi @srenatus! |
c450cf5 to
4c0030d
Compare
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
4c0030d to
69d13b7
Compare
|
I just noticed that @srenatus is on parental leave. Sorry for the disturbance. /cc @JoelSpeed @bonifaido @rithujohn191 |
JoelSpeed
left a comment
There was a problem hiding this comment.
Seems sensible to me, one quick question, I don't mind this style just curious as to why you went for it 🙂
| //relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css" | ||
| func relativeURL(serverPath, reqPath, assetPath string) string { | ||
|
|
||
| splitPath := func(p string) []string { |
There was a problem hiding this comment.
Any reason to define this and stripCommonParts as a local variable rather than an unexported method in the package?
There was a problem hiding this comment.
Thanks a lot for the review @JoelSpeed 😄
I defined them as closures inside the relativeURL function because their scope was that specific function.
That is, they are not used elsewhere.
Fixes #1553
This PR makes sure every template refers to its local assets using a URL relative to the request's URL.
For example:
server listens at localhost/dex so serverPath is dex
reqPath is /dex/auth
assetPath is static/main.css
relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css"
I had to propagate the request's path from each handler down to the templates' data.
I chose to pass the whole http request as a parameter to the template render functions, as it may contain other useful information in the future (eg values from context).
I can change it to only pass down the request's path if it's preferable.
Signed-off-by: Yannis Zarkadas yanniszark@arrikto.com