LoginSignup
10
8

More than 5 years have passed since last update.

reserve を使ってホットリロードしながらWebアプリを開発する方法

Posted at

reserve というツールを使うとHaskellでホットリロードしながらWebアプリを開発することが出来ます。

インストールは

$ git clone git@github.com:sol/reserve.git
$ cd reserve
$ cabal sandbox init
$ cabal install --only-dependencies
$ cabal build

とすると./dist/build/reserve/reserveというバイナリが出来あがります。使い方は簡単で公式のREADMEがとても参考になります。
ここではStackと一緒に使う方法を紹介します。試しに以下の様なプロジェクトを作ります。

$ stack new web-app
web-app.cabal
name:                web-app
version:             0.1.0.0

executable web-app-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , scotty
  default-language:    Haskell2010
app/Main.hs
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty

main :: IO ()
main = scotty 3000 $ do
  get "/" $ do
    text "hello\n"

次のように実行します

$ stack exec -- ../reserve/dist/build/reserve/reserve app/Main.hs
http://localhost:12000

これでhttp://localhost:12000にアクセスするとhelloと表示されると思います。この状態でアプリを落とさずにファイルを以下のように変更してみましょう。

main = scotty 3000 $ do
   get "/" $ do
     text "hello\n"
+  get "/hello" $ do
+    text "world\n"

そしてhttp://localhost:12000/helloにアクセスするとちゃんとworldと表示されると思います。

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8