You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: Need more use-case ideas before actually implementing this.
Prefix mounting matches request.paths that start with a given prefix, except that the prefix is then removed from the request.path before being passed to the mounted middleware.
In other words, the mounted middleware do not know about the prefix.
The following router unfortunately queries the filesystem for every request to see if the request hits a file in the public static assets folder.
val router =Router (serveStatic("public")) {
get("/") { Response().text("homepage")
}
Prefix mounting would let us rewrite that router to limit the serveStatic middleware only to requests with paths that start with /assets, yet without requiring any other changes to our filesystem hierarchy or the public folder.
Now, a request GET /assets/img/flower.png would trigger the serveStatic middleware, yet it will look up public/img/flower.png (doesn't see the /assets prefix) and serve the file if it exists.
If serveStatic does not handle the request, then the request is passed down the chain as usual with downstream middleware/handlers seeing the prefixed route.
The text was updated successfully, but these errors were encountered:
Note: Need more use-case ideas before actually implementing this.
Prefix mounting matches
request.path
s that start with a given prefix, except that the prefix is then removed from therequest.path
before being passed to the mounted middleware.In other words, the mounted middleware do not know about the prefix.
The following router unfortunately queries the filesystem for every request to see if the request hits a file in the
public
static assets folder.Prefix mounting would let us rewrite that router to limit the
serveStatic
middleware only to requests with paths that start with/assets
, yet without requiring any other changes to our filesystem hierarchy or thepublic
folder.Now, a request
GET /assets/img/flower.png
would trigger theserveStatic
middleware, yet it will look uppublic/img/flower.png
(doesn't see the/assets
prefix) and serve the file if it exists.If
serveStatic
does not handle the request, then the request is passed down the chain as usual with downstream middleware/handlers seeing the prefixed route.The text was updated successfully, but these errors were encountered: