Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue #18, broken links when urls have a trailing slash

  • Loading branch information...
commit ec6adfe8b7731436d9aeacd8f3bd560476f052e9 1 parent 108e23c
@mightybyte mightybyte authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/Main.hs
View
17 src/Main.hs
@@ -13,9 +13,8 @@ import Control.Monad.Trans
import qualified Data.ByteString.Char8 as B
import Data.Lens.Template
import Data.Maybe
-import Data.Text (Text)
import qualified Data.Text as T
-import qualified Data.Text.Encoding as T
+import Data.Text.Encoding
import Data.Time.Clock.POSIX
import Foreign.C.Types
import Prelude hiding (catch)
@@ -44,8 +43,12 @@ epochTime = do
return $ fromInteger $ truncate t
-description :: Text
-description = "The snapframework.com website"
+undirify :: MonadSnap m => m ()
+undirify = do
+ uri <- withRequest (return . rqURI)
+ if B.length uri > 1 && T.last (decodeUtf8 uri) == '/'
+ then redirect (B.init uri)
@gregorycollins Owner

Although it fixes the broken link, this is exactly backwards from what should happen here :(

@mightybyte Owner

That's why I put off doing it. I think there are arguments for both approaches. This approach seemed a good bit easier to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ else return ()
appInit :: SnapletInit App App
@@ -56,8 +59,10 @@ appInit = makeSnaplet "snap-website" description Nothing $ do
, ("feed-autodiscovery-link", liftHeist $ textSplice "")
]
wrapHandlers (\h -> catch500 $ withCompression $
- h <|> setCache (serveDirectory "static"))
+ undirify >> h <|> setCache (serveDirectory "static"))
return $ App hs bs
+ where
+ description = "The snapframework.com website"
setCache :: MonadSnap m => m a -> m ()
@@ -90,7 +95,7 @@ catch500 m = (m >> return ()) `catch` \(e::SomeException) -> do
serverVersion :: SnapletSplice b v
-serverVersion = liftHeist $ textSplice $ T.decodeUtf8 snapServerVersion
+serverVersion = liftHeist $ textSplice $ decodeUtf8 snapServerVersion
main :: IO ()
Please sign in to comment.
Something went wrong with that request. Please try again.