From 04d9f063d418e64ede948641f645ade69f2b602d Mon Sep 17 00:00:00 2001 From: Dennis Frieberg Date: Wed, 23 Sep 2020 20:48:03 +0200 Subject: [PATCH] backends should work now (but untested) --- README.md | 14 ++++++++++++++ app/Main.hs | 35 ++++++++++++++++++++++++++++++++--- package.yaml | 27 +++++++++++++++++++++++++-- stack.yaml | 1 + stack.yaml.lock | 9 ++++++++- tickLeisteServer.cabal | 38 +++++++++++++++++++++++++++++++++----- 6 files changed, 113 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8b69848..32e9a72 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ # tickLeisteServer + +You should enable at least one backend (else the application will terminate +upon execution) this is done by setting a flag. The options are + +http +https +fast-cgi +cgi + +fast-cgi depends on the fcgi C library, which should be installed on your system + +TODO: +can we use multiple backends at once? +write configuration documentation. diff --git a/app/Main.hs b/app/Main.hs index 9bb883a..00c8593 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -7,11 +7,40 @@ module Main where -- TODO: -- We need some way too configure things, like the port we run on. -- see Network.Wai.Handler.Warp.Settings and Network.Wai.Handler.Warp.runSettings -import WaiApp + import Control.Concurrent.MVar -import Network.Wai.Handler.Warp +import WaiApp + +#ifdef HTTP_SUPPORT +import qualified Network.Wai.Handler.Warp as HTTP +#endif + +#ifdef HTTPS_SUPPORT +import qualified Network.Wai.Handler.WarpTLS as HTTPS +import qualified Network.Wai.Handler.Warp as HTTP +#endif + +#ifdef FASTCGI_SUPPORT +import qualified Network.Wai.Handler.FastCGI as FastCGI +#endif + +#ifdef CGI_SUPPORT +import qualified Network.Wai.Handler.CGI as CGI +#endif main :: IO () main = do serverState <- newMVar newServerState - run 8080 $ waiApplication serverState +#ifdef HTTP_SUPPORT + HTTP.runSettings HTTP.defaultSettings $ waiApplication serverState +#endif +#ifdef HTTPS_SUPPORT + HTTPS.runTLS HTTPS.defaultTlsSettings HTTP.defaultSettings $ waiApplication serverState +#endif +#ifdef FASTCGI_SUPPORT + FastCGI.run $ waiApplication serverState +#endif +#ifdef CGI_SUPPORT + CGI.run $ waiApplication serverState +#endif + return () diff --git a/package.yaml b/package.yaml index 135a8c2..3385bde 100644 --- a/package.yaml +++ b/package.yaml @@ -29,7 +29,7 @@ flags: manual: true default: false fast-cgi: - description: Build with fastcgi support + description: Build with fastcgi support -- this depends on the fcgi c library manual: true default: false cgi: @@ -49,12 +49,22 @@ dependencies: - containers - wai - wai-websockets +- http-types when: - condition: flag(http) dependencies: - - http-types - warp + - condition: flag(https) + dependencies: + - warp-tls + - warp + - condition: flag(fast-cgi) + dependencies: + - wai-handler-fastcgi + - condition: flag(cgi) + dependencies: + wai-extra build-tools: - cpphs @@ -70,6 +80,19 @@ executables: - -cpp - -pgmP cpphs - -optP --cpp + when: + - condition: flag(http) + cpp-options: + - -DHTTP_SUPPORT + - condition: flag(https) + cpp-options: + - -DHTTPS_SUPPORT + - condition: flag(fast-cgi) + cpp-options: + - -DFASTCGI_SUPPORT + - condition: flag(cgi) + cpp-options: + - -DCGI_SUPPORT tests: tickLeisteServer-test: diff --git a/stack.yaml b/stack.yaml index 3342ba6..860c91f 100644 --- a/stack.yaml +++ b/stack.yaml @@ -38,6 +38,7 @@ packages: extra-deps: - tickLeiste/tickLeiste - tickLeiste/tickLeiste-aeson +- wai-handler-fastcgi-3.0.0.2@sha256:ecf5b5bd7e493b361df9099c190b6ca8f2fb5a467a2a5efa271b7f52d4d82986,1136 # - acme-missiles-0.3 # - git: https://github.com/commercialhaskell/stack.git # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a diff --git a/stack.yaml.lock b/stack.yaml.lock index b10e8c4..81d2869 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -3,7 +3,14 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] +packages: +- completed: + hackage: wai-handler-fastcgi-3.0.0.2@sha256:ecf5b5bd7e493b361df9099c190b6ca8f2fb5a467a2a5efa271b7f52d4d82986,1136 + pantry-tree: + size: 442 + sha256: d090422c36807ef5838f72fa74efcc211c528c5ba84e5a5114f6a3cf4ec685f4 + original: + hackage: wai-handler-fastcgi-3.0.0.2@sha256:ecf5b5bd7e493b361df9099c190b6ca8f2fb5a467a2a5efa271b7f52d4d82986,1136 snapshots: - completed: size: 532380 diff --git a/tickLeisteServer.cabal b/tickLeisteServer.cabal index da8a79b..22b02d7 100644 --- a/tickLeisteServer.cabal +++ b/tickLeisteServer.cabal @@ -29,7 +29,7 @@ flag cgi default: False flag fast-cgi - description: Build with fastcgi support + description: Build with fastcgi support -- this depends on the fcgi c library manual: True default: False @@ -59,6 +59,7 @@ executable tickLeisteServer , base >=4.7 && <5 , bytestring , containers + , http-types , text , tickLeiste , tickLeiste-aeson @@ -68,8 +69,25 @@ executable tickLeisteServer , websockets if flag(http) build-depends: - http-types - , warp + warp + if flag(https) + build-depends: + warp + , warp-tls + if flag(fast-cgi) + build-depends: + wai-handler-fastcgi + if flag(cgi) + build-depends: + wai-extra + if flag(http) + cpp-options: -DHTTP_SUPPORT + if flag(https) + cpp-options: -DHTTPS_SUPPORT + if flag(fast-cgi) + cpp-options: -DFASTCGI_SUPPORT + if flag(cgi) + cpp-options: -DCGI_SUPPORT default-language: Haskell2010 test-suite tickLeisteServer-test @@ -87,6 +105,7 @@ test-suite tickLeisteServer-test , base >=4.7 && <5 , bytestring , containers + , http-types , text , tickLeiste , tickLeiste-aeson @@ -97,6 +116,15 @@ test-suite tickLeisteServer-test , websockets if flag(http) build-depends: - http-types - , warp + warp + if flag(https) + build-depends: + warp + , warp-tls + if flag(fast-cgi) + build-depends: + wai-handler-fastcgi + if flag(cgi) + build-depends: + wai-extra default-language: Haskell2010