@@ -1,8 +1,23 @@
11{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances #-}
2+{- | This module gives you a way to mount applications under sub-URIs.
3+For example:
4+
5+> myApp :: Application
6+> myApp = mapUrls $
7+> mount "bugs" bugsApp
8+> <|> mount "helpdesk" helpdeskApp
9+> <|> mount "api"
10+> ( mount "v1" apiV1
11+> <|> mount "v2" apiV2
12+> )
13+> <|> mountRoot mainApp
14+
15+-}
216module Network.Wai.UrlMap (
17+ UrlMap',
318 UrlMap,
4− mount,
519 mount',
20+ mount,
621 mountRoot,
722 mapUrls
823) where
@@ -34,17 +49,19 @@ instance Alternative UrlMap' where
3449
3550type UrlMap = UrlMap' Application
3651
37−-- | Mount an application under a given path.
52+-- | Mount an application under a given path. The ToApplication typeclass gives
53+-- you the option to pass either an 'Network.Wai.Application' or an 'UrlMap'
54+-- as the second argument.
3855mount' :: ToApplication a => Path -> a -> UrlMap
3956mount' prefix thing = UrlMap' [(prefix, toApplication thing)]
4057
41−-- A little helper function, since most of the time, apps are mounted under
42−-- a single path segment.
58+-- | A convenience function like mount', but for mounting things under a single
59+-- path segment.
4360mount :: ToApplication a => Text -> a -> UrlMap
4461mount prefix thing = mount' [prefix] thing
4562
46−-- Another little helper function. Use this for the last mounted
47−-- application in the block, to avoid 500 errors from none matching.
63+-- | Mount something at the root. Use this for the last application in the
64+-- block, to avoid 500 errors from none of the applications matching.
4865mountRoot :: ToApplication a => a -> UrlMap
4966mountRoot = mount' []
5067