Reputation: 9051
I am trying to learn Ktor, when responding to a GET request, I found that the trailing slash is treated as two routes, for example:
/greet?name=john
/greet/?name=john
Is it possible to define one route for the above two URLs, which is to handle trailing slash automatically?
Upvotes: 6
Views: 1124
Reputation: 420
Be careful when using install(IgnoreTrailingSlash) with static content, as omitting the trailing slash will result in a base url without the final path segment.
For example, let's say I have something like this in my routing code...
staticResources("/static", "static")
get("/myendpoint")
And an html file, which imports some javascript...
<script type="module" src="static/index.js"></script>
The import will fail with the trailing slash.
Upvotes: 0
Reputation: 103
In your Application.module()
or Application.configureRouting()
add this:
install(IgnoreTrailingSlash)
Upvotes: 10
Reputation: 6999
You can use the IgnoreTrailingSlash plugin to solve your problem.
Upvotes: 6