Snap Web Framework中的自定义404

时间:2013-10-11 01:56:49

标签: haskell haskell-snap-framework

我正在使用Snap构建一个网站。如何指定自定义404处理程序以捕获所有不存在的路由?

我想重新定义默认值:

No handler accepted "/asdfasdf"

由于

1 个答案:

答案 0 :(得分:4)

修改路由行为的正确方法是使用wrapSite

wrapSite (\site -> site <|> writeBS "Use your custom 404 handler" )

在示例代码中,您可以在基本初始化程序中添加此行。在Snap Init代码中,它将位于do app函数中。


同样""将匹配给定的任何路线。例如:

routes = [ ("/login",    with auth handleLoginSubmit)
         , ("/logout",   with auth handleLogout)
         , ("/new_user", with auth handleNewUser)
         , ("/static", serveDirectory "static")
         , ("",        writeBS "This if none of the others" )
         ]

您可以将""的处理程序更改为自定义404。

相关问题