Spock
Spock copied to clipboard
Route with trailing slash
Is there a way to have different actions for /foo/bar/
and /foo/bar
?
In my situation specificaly, I want all /foo/bar
reuest be redirected to /foo/bar/
so relative paths on frontend lead to /foo/bar/baz
instead of /foo/baz
Currently there is not, this is normalized. If you'd like you could implement the behavior behind some configuration and send a PR :-)
Unfortunately I'm not too familiar with Spock's internal structure to do implement something like that.
Currently I have this ~~hack~~ workaround: I just take the raw path and see if there was a trailing slash.
directoryHook :: MonadIO m => ActionCtxT ctx m () -> ActionCtxT ctx m ()
directoryHook action = do
rawPath <- T.decodeUtf8 . rawPathInfo <$> request
if T.last rawPath /= '/'
then redirect $ rawPath <> "/"
else action
Nice! I'll look into the real issue as I find time for it :-)