https://kotlinlang.org logo
#ktor
Title
# ktor
f

foxx1337

03/15/2020, 3:03 PM
Is it possible to configure ktor to automatically insert a trailing slash for requests on
static
directories? I got
Copy code
static("ui") {
            resources("swagger-ui")
            resource("api.json")
            defaultResource("swagger-ui/index.html")
        }
and when I browse the server at
server/path/to/ui
I actually see that
index.html
file (direct 200, no reidrects) but I see none of the static resources the
index.html
tries to load (it addresses them like
./resource
). Those static resources load just fine if I navigate to
server/path/to/ui/
(notice the trailing slash).
g

Gunslingor

03/15/2020, 4:54 PM
I'm not sure what your really asking, it sounds like the wrong question though honestly. I've been just learning this last night actually, figured it out, I suspect thge screenshot should clarify for you and this is how you use it with HTML DSL:
Copy code
head {
        title { +"Async World" }
        script {
            attributes["type"]=ScriptType.textJavaScript
            attributes["src"]="resource/three.min.js"
        }
    }
That's what my last post was about, lol. If there is a better way let me know!
f

foxx1337

03/15/2020, 9:53 PM
Yeah, so the
index.html
provided by swagger-ui tries to read images, js and css files by adressing them like
img src="./picture.png"
. Because ktor doesn't issue the redirect from
/path/to/ui
towards
/path/to/ui/
, the browser ends up trying to load
/path/to/picture.png
instead of
/path/to/ui/picture.png
.
g

Gunslingor

03/15/2020, 9:55 PM
never tried swagger sorry homie
f

foxx1337

03/16/2020, 7:34 AM
It's not a swagger issue, it's an issue of ktor not sending the 301 permanently moved for
folder
towards
folder/
.
j

Joe

03/16/2020, 2:46 PM
We've updated the links in index.html to server absolute instead of relative (eg /swagger-ui/picture.png instead of ./picture.png) to make this work
f

foxx1337

03/16/2020, 2:48 PM
That's fair and I'm doing it as well now. Just wondering whether it's achievable from ktor. nginx does it by default for example (forcing the 301 redirect towards
url + '/'
).
2 Views