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

wai-app-static directory listings and Yesod #988

Closed
gregwebs opened this issue May 12, 2015 · 3 comments
Closed

wai-app-static directory listings and Yesod #988

gregwebs opened this issue May 12, 2015 · 3 comments

Comments

@gregwebs
Copy link
Member

This is a minor inconsistency that I just noticed. Yesod's default cleanPath will eliminate trailing slashes and the user will be redirected to the clean version. The wai-app-static library has a directory listing feature. So, if I use this:

return $ Yesod.Static.Static $ defaultFileServerSettings $ decodeString "mystatic"

The directory listing is on and I should be able to freely use my web browser to poke around in the static subsite. But, there is a trap. Unfortunately, wai-app-static has a different idea of what a "clean" path is. In particular, if you try to browse a directory, it wants to add a slash to the path. This means that combining this feature with Yesod's defaults gives us a redirect loop. The fix is obvious:

cleanPath _ s = if corrected == s || headMay s == Just "mystatic" 
    then Right $ map dropDash s              
    else Left corrected
  where      
    corrected = filter (not . Text.null) s                                                        
    dropDash t 
        | Text.all (== '-') t = Text.drop 1 t
        | otherwise = t

But, I feel like the two should work together by default. Maybe a change to wai-app-static would be appropriate because I really do like that Yesod drops the trailing slashes. Any thoughts?

@gregwebs
Copy link
Member Author

originally opened by @andrewthad at yesodweb/persistent#384

@meteficha
Copy link
Member

If I could choose a convention without thinking about how it would be implemented, I'd say that wai-app-static should continue adding trailing slashes to directories while the rest of the Yesod web app should continue to be able to choose whether their routes contain trailing slashes or not.

However, knowing the details of how subsites are setup, the easiest solution is probably to make a switch on wai-app-static disabling all redirects due to trailing slashes, and make this the default. The application containing the wai-app-static subsite is then able to choose whatever convention for everything.

@snoyberg
Copy link
Member

This should be resolved by yesodweb/wai@f0caeb2

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

No branches or pull requests

3 participants