lewis
10/19/2019, 11:04 AMlewis
10/19/2019, 11:07 AMlewis
10/19/2019, 11:28 AMstatus(HttpStatusCode.NotFound) {
if(call.request.accept()?.contains("text/html", ignoreCase = true) == true) {
val content = call.resolveResource("index.html", "static")
if(content != null) call.respond(HttpStatusCode.OK, content)
} else {
call.respond(HttpStatusCode.NotFound, "Not found")
}
}
Is this the best way to do this?wilyarti
10/20/2019, 8:29 AMavolkmann
10/20/2019, 9:15 AMlewis
10/22/2019, 12:33 PMdefaultResource("index.html", "static")
for serving my index.html
page on /
, however, HTML5 history works by changing the URL client side.
For example, my SPA may have a route for /login
, however, this route is not present in ktor - the route only exists in Vue. HTML5 history requires that any paths that would have resulted in a 404, instead serve the index.html
- so if a user were to refresh /login
it ktor should just return index.html
and Vue will handle the route accordingly.
@avolkmann no dice, file("{...}", "index.html")
in my static {}
block I only see a 404 for routes undefined in ktor (e.g. /noroute
). I tried your other suggestions, but I've so far been unsuccessful.
The closest I've been able to get is this, but it just returns index.html
for everything 😛
I hoped that the routing would have been smart enough to execute the tailcard last, but this doesn't seem to be the case.lewis
10/22/2019, 12:33 PMlewis
10/22/2019, 1:41 PMwilyarti
10/23/2019, 1:14 AM