Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route with trailing slash #112

Open
Hithroc opened this issue Feb 28, 2017 · 3 comments
Open

Route with trailing slash #112

Hithroc opened this issue Feb 28, 2017 · 3 comments

Comments

@Hithroc
Copy link

Hithroc commented Feb 28, 2017

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

@agrafix
Copy link
Owner

agrafix commented Mar 1, 2017

Currently there is not, this is normalized. If you'd like you could implement the behavior behind some configuration and send a PR :-)

@Hithroc
Copy link
Author

Hithroc commented Mar 2, 2017

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

@agrafix
Copy link
Owner

agrafix commented Mar 2, 2017

Nice! I'll look into the real issue as I find time for it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants