This is a barebones Snap server. It contains a few routes and shows how a more complicated website could be constructed.
The image is available on the docker registry:
docker pull snapforbeginners/barebones
The Snap server runs on port 8000
, so we'll use that same port on
the host:
docker run -it -p 8000:8000 snapforbeginners/barebones
To build a new image, we need to clone this repository and run docker build
.
git clone git@github.com:snapforbeginners/barebones.git
cd barebones
docker build -t barebones .
then we can run it as before:
docker run -it -p 8000:8000 barebones
- Run the image using:
docker run -it -p 8000:8000 snapforbeginners/barebones
Access the container by typing in eitherboot2docker ip
orlocalhost
into the browser's URL bar. (ex:localhost:8000
) - getParam
- We can add a handler to the end of the chain that has no routing restrictions:
site :: Snap ()
site =
ifTop (writeBS "hello world") <|>
route [ ("foo", writeBS "bar")
, ("echo/:echoparam", echoHandler)
] <|>
dir "static" (serveDirectory "/opt/server/static") <|>
catchAll
catchAll :: Snap ()
catchAll = writeBS "An error occurred"