6

Given a freshly scaffolded Yesod application, what is the minimal set of changes necessary to get an executable which acts as a CGI program? A wrapper program is acceptable. If the default executable built by 'cabal build' is a CGI program, what environment variables must be set for it to act as a CGI (as by default it will bind to a port and attempt to serve requests there.)

A similar answer for FastCGI would also be appreciated.

Edward Z. Yang
  • 26,325
  • 16
  • 80
  • 110

1 Answers1

7

Update your app/main.hs with the following:

import Prelude              (IO, (>>=))
import Yesod.Default.Config (fromArgs)
import Yesod.Default.Main   (defaultMain)
import Settings             (parseExtra)
import Application          (makeApplication)
import Network.Wai.Handler.CGI (run)

main :: IO ()
main = fromArgs parseExtra >>= makeApplication >>= run

You'll need to add wai-extra to the dependencies in your cabal file. To use FastCGI instead, replace Network.Wai.Handler.CGI with Network.Wai.Handler.FastCGI and add wai-handler-fastcgi to the dependency list instead.

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
  • Does this break 'yesod devel'? – Edward Z. Yang Oct 28 '12 at 21:30
  • 1
    Just to clarify why: the scaffolded site is built as a library which (essentially) provides an `IO Application`. Then there are two executables: `main.hs` is used for production and `devel.hs` is used for `yesod devel`. So the changes to `main.hs` have no effect on development. – Michael Snoyman Oct 29 '12 at 04:32