Snap 1.0 isn’t on Hackage yet, but here’s how you can play with it now.
NOTE: This was written using ghc-7.8.3. The repo is on GitHub
First we’ll make a new directory for the project and one for the dependencies, then clone the dependencies for 1.0 that aren’t on Hackage:
<code class="bash" style="overflow-x:auto">mkdir auth_servercd auth_servermkdir depsgit clone git@github.com:snapframework/io-streams-haproxy.git deps/io-streams-haproxygit clone git@github.com:snapframework/snap.git deps/snapgit clone git@github.com:snapframework/snap-core.git deps/snap-coregit clone git@github.com:snapframework/snap-server.git deps/snap-servergit clone git@github.com:snapframework/snap-loader-static.git deps/snap-loader-staticgit clone git@github.com:snapframework/heist.git deps/heistgit clone git@github.com:snapframework/snap-templates.git deps/snap-templates
We should have a file structure that looks like this:
We can now get a scaffolded app using snap-templates
.
<code class="bash">cd auth_server/deps/snap-templatescabal build
Building snap-templates
gives us the snap
executable
that we used to use from the snap
project. In the project
root, let’s init a new scaffold:
<code class="bash">cd auth_server./deps/snap-templates/dist/build/snap/snap init
Which leaves us with this structure at the top level:
If you haven’t created a new sandbox for this project, do that now and install the dependencies for the scaffold into the sandbox.
<code class="bash">cd auth_servercabal sandbox initcabal install --only-dependencies
We can’t build the app yet, since the scaffold is missing
two things. We need to add map-syntax
as a dependency to
auth-server.cabal
and we need to replace noSplices
with
mempty
in Site.hs
since noSplices
has been deprecated.
First, in auth-server.cabal
, under Build-depends
add
map-syntax
:
xmlhtml >= 0.1,map-syntax >= 0.1
Next, we need to add two imports to src/Site.hs
:
<code class="haskell">import Data.Map.Syntaximport Data.Monoid (mempty)
as well as replace noSplices
with mempty
:
Before:
errs = maybe noSplices splice authError
After:
errs = maybe mempty splice authError
We can now build and run the project:
cd auth_servercabal build./dist/build/auth-server/auth-server
We now have a working Snap 1.0 app to play with. In a future blog post, we’ll explore the creation of a Users service.