Permalink
Browse files

make log if not there

  • Loading branch information...
1 parent 742e80e commit 930f616eeaeb089a1d4047555fb084e1cc3321fa @nfjinjing committed Jun 21, 2011
Showing with 30 additions and 15 deletions.
  1. +3 −0 .gitignore
  2. +1 −1 Nemesis
  3. +4 −3 hack2-handler-snap-server.cabal
  4. +18 −10 src/Hack2/Handler/SnapServer.hs
  5. +4 −1 test/ab.hs
View
@@ -9,3 +9,6 @@
/dist
.nemesis
+
+
+log
View
@@ -32,7 +32,7 @@ nemesis = do
desc "test ab"
task "ab" $ do
- sh "runghc test/ab.hs"
+ sh "runghc -isrc test/ab.hs"
desc "show sloc"
@@ -1,5 +1,5 @@
Name: hack2-handler-snap-server
-Version: 2011.6.20.1
+Version: 2011.6.21
Build-type: Simple
Synopsis: Hack2 Snap server handler
Description: Hack2 Snap server handler
@@ -27,9 +27,10 @@ library
, blaze-builder < 0.4
, case-insensitive < 0.3
, air
- , safe
+ , snap-core
+ , snap-server
hs-source-dirs: src/
exposed-modules:
- Hack2.Handler.Warp
+ Hack2.Handler.SnapServer
@@ -6,17 +6,17 @@
module Hack2.Handler.SnapServer
(
--- run
--- , runWithConfig
--- , ServerConfig(..)
--- , hackAppToWaiApp
+ run
+, runWithConfig
+, runWithSnapServerConfig
+, ServerConfig(..)
+, hackAppToSnap
) where
import Prelude ()
import Air.Env hiding (def, Default)
-import qualified Network.Wai as Wai
import Hack2
import Data.Default (def, Default)
import qualified Data.CaseInsensitive as CaseInsensitive
@@ -26,8 +26,6 @@ import Data.Enumerator (Enumerator, Iteratee (..), ($$), joinI, run_, Enumeratee
import qualified Data.Enumerator.List as EL
import Blaze.ByteString.Builder (Builder, fromByteString, fromLazyByteString)
-import qualified Safe as Safe
-
import qualified Snap.Types as Snap
import qualified Snap.Internal.Http.Types as SnapInternal
@@ -37,6 +35,9 @@ import Data.Map (toAscList, fromAscList)
import Data.IORef (readIORef)
import qualified Snap.Http.Server as SnapServer
+import System.Directory (createDirectory, doesDirectoryExist)
+import Control.Monad (when)
+
{-
{ requestMethod :: RequestMethod
@@ -64,7 +65,7 @@ requestToEnv request = do
{
requestMethod = request.Snap.rqMethod.snapMethodToHackMethod
-- , scriptName = request.SnapInternal.rqSnapletPath
- , pathInfo = request.Snap.rqPathInfo
+ , pathInfo = B.append "/" - request.Snap.rqPathInfo
, queryString = request.Snap.rqQueryString -- .B.dropWhile (is '?')
, serverName = request.Snap.rqServerName
, serverPort = request.Snap.rqServerPort
@@ -147,9 +148,16 @@ runWithSnapServerConfig snap_server_config app = do
runWithConfig :: ServerConfig -> Application -> IO ()
-runWithConfig config app =
+runWithConfig config app = do
let snap_config = SnapServer.emptyConfig.SnapServer.setPort (config.port)
- in
+
+ snap_default_log_path = "log"
+
+ log_directory_exist <- doesDirectoryExist snap_default_log_path
+ when (not - log_directory_exist) -
+ createDirectory snap_default_log_path
+
+
runWithSnapServerConfig snap_config app
View
@@ -9,6 +9,7 @@ import Data.Default (def)
import Data.ByteString.Lazy.Char8 (pack)
import Air.Env hiding (def)
+import Air.Extra
import Prelude ()
import Control.Monad (forever)
@@ -22,9 +23,11 @@ app = simple_access_logger Nothing - \env ->
main = do
fork - do
- putStrLn - "warp started at port 3001"
+ putStrLn - "snap server started at port 3001"
SnapServer.runWithConfig def {SnapServer.port = 3001} app
+ sleep 1
+
fork - do
putStrLn - "happstack started at port 3000"
HappstackServer.run app

0 comments on commit 930f616

Please sign in to comment.