I'm struggling to understand how to use the path::param
filter in warp. This may in fact be an XY problem, where the problem is not with path::param
but in the approach to the task overall. Right now I have two static pages. I'd like to serve them both at the same path depending upon parameter presence. When no param is present it should serve the login page. This page uses oauth2 to return a redirect url with token parameters.
The simplest task is to check if a param is present and serve the logged-in user page. Of course ideally I'd like to figure out how to parse the various params and pass that info to the logged-in user page correctly, but for now I'm just trying to get two different files at the same path.
If I just define my route as warp::get2().and(warp::path("mypath").and(warp::fs::file("my/file/path/myfile.html")
then warp serves myfile
at /mypath
and at any /mypath#param1=foo¶m2=bar...
. I clearly don't understand what warp::path::param
is for because I expect to be able to do something like
warp::get2().and(warp::path("mypath")
.and(warp::path::param::<String>())
.map(| param | if param.is_empty()
{ warp::fs::file("my/file/path/myfile.html")
} else
{ warp::fs::file("my/file/path/myOTHERfile.html")
})
But this does not work. How would one accomplish what I'm trying to do with warp?