Main: show 404 page if path is not found
This commit is contained in:
parent
0fa42c588c
commit
d427db124f
|
@ -5,6 +5,8 @@ module Main where
|
||||||
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
import Data.Text (Text)
|
||||||
|
import qualified Data.Text as Text
|
||||||
import qualified Database.SQLite.Simple as Db
|
import qualified Database.SQLite.Simple as Db
|
||||||
import qualified Network.HTTP.Types.Status as Status
|
import qualified Network.HTTP.Types.Status as Status
|
||||||
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
|
||||||
|
@ -35,6 +37,16 @@ main = do
|
||||||
S.middleware $ Static.staticPolicy $ Static.addBase "public"
|
S.middleware $ Static.staticPolicy $ Static.addBase "public"
|
||||||
S.middleware $ RequestLogger.logStdout
|
S.middleware $ RequestLogger.logStdout
|
||||||
|
|
||||||
|
-- 404 handler
|
||||||
|
S.hookAny S.GET $ \(paths :: [Text]) ->
|
||||||
|
let slash = Text.pack "/"
|
||||||
|
path = Text.append slash $ Text.intercalate slash paths
|
||||||
|
message = "No such page at " ++ (Text.unpack path)
|
||||||
|
page = ErrorView.render message
|
||||||
|
title = "Page not found"
|
||||||
|
|
||||||
|
in S.html $ wrapMarkupStringTitle title page
|
||||||
|
|
||||||
-- Test routes
|
-- Test routes
|
||||||
S.get S.root $
|
S.get S.root $
|
||||||
S.html $ wrapMarkup "The OP" (Post.render h user)
|
S.html $ wrapMarkup "The OP" (Post.render h user)
|
||||||
|
@ -63,3 +75,5 @@ main = do
|
||||||
page = Thread.render id_ posts userMap
|
page = Thread.render id_ posts userMap
|
||||||
|
|
||||||
S.html $ wrapMarkupStringTitle title page
|
S.html $ wrapMarkupStringTitle title page
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue