[added Dir2 and Dirs Jeremy Shaw **20100517204453 Ignore-this: 97c966d2939c5102e7c89e25a5a973a1 ] hunk ./Dir.lhs 14 -> import Happstack.Server (nullConf, simpleHTTP, toResponse, ok, dir, path, nullDir, methodM) +> import Happstack.Server (nullConf, simpleHTTP, ok, dir) hunk ./Dir.lhs 24 + + addfile ./Dir2.lhs hunk ./Dir2.lhs 1 + + +

Using dir to match on multiple components

+ +

We can match on multiple components by chaining calls to dir together

+ +> module Main where +> +> import Control.Monad (msum) +> import Happstack.Server (nullConf, simpleHTTP, ok, dir) +> +> main :: IO () +> main = simpleHTTP nullConf $ msum [ dir "hello" $ dir "world" $ ok "Hello, World!" +> , dir "goodbye" $ dir "moon" $ ok "Goodbye, Moon!" +> ] + +

Source code for the app is here.

+ +

If we start the app and point our browser at http://localhost:8000/hello/world we get the hello message, and if we point it at http://localhost:8000/goodbye/moon, we get the goodbye message.

+ addfile ./Dirs.lhs hunk ./Dirs.lhs 1 + + +

Using dirs as shorthand to match on multiple components

+ +

As a shorthand, we can also use dirs to handle multiple static patch components.

+ +> module Main where +> +> import Control.Monad (msum) +> import Happstack.Server (nullConf, simpleHTTP, ok, dirs) +> +> main :: IO () +> main = simpleHTTP nullConf $ msum [ dirs "hello/world" $ ok "Hello, World!" +> , dirs "goodbye/moon" $ ok "Goodbye, Moon!" +> ] + +

Source code for the app is here.

+ +

If we start the app and point our browser at http://localhost:8000/hello/world we get the hello message, and if we point it at http://localhost:8000/goodbye/moon, we get the goodbye message.

+ hunk ./Makefile 6 -DEMOS := Dir.lhs +DEMOS := Dir.lhs Dir2.lhs Dirs.lhs hunk ./Makefile 11 -RouteFilters.lhs: Dir.lhs - hunk ./Makefile 13 +RouteFilters.lhs: Dir.lhs Dir2.lhs Dirs.lhs + hunk ./RouteFilters.lhs 26 +#include "Dir2.lhs" +#include "Dirs.lhs"