From 4135032677592f4a3a16ecd3c9506e569abe6f75 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2012 12:20:37 +0200 Subject: [PATCH] wai-handler-launch: runUrlPort --- .../Network/Wai/Handler/Launch.hs | 18 +++++++++++------- wai-handler-launch/wai-handler-launch.cabal | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wai-handler-launch/Network/Wai/Handler/Launch.hs b/wai-handler-launch/Network/Wai/Handler/Launch.hs index 0515fd69..8a9535a7 100644 --- a/wai-handler-launch/Network/Wai/Handler/Launch.hs +++ b/wai-handler-launch/Network/Wai/Handler/Launch.hs @@ -4,6 +4,7 @@ module Network.Wai.Handler.Launch ( run , runUrl + , runUrlPort ) where import Network.Wai @@ -125,32 +126,35 @@ foreign import ccall "launch" launch' :: Int -> CString -> IO () #endif -launch :: String -> IO () +launch :: Int -> String -> IO () #if WINDOWS -launch s = withCString s $ launch' 4587 +launch port s = withCString s $ launch' port #else -launch s = forkIO (rawSystem +launch port s = forkIO (rawSystem #if MAC "open" #else "xdg-open" #endif - ["http://127.0.0.1:4587/" ++ s] >> return ()) >> return () + ["http://127.0.0.1:" ++ show port ++ "/" ++ s] >> return ()) >> return () #endif run :: Application -> IO () run = runUrl "" runUrl :: String -> Application -> IO () -runUrl url app = do +runUrl = runUrlPort 4587 + +runUrlPort :: Int -> String -> Application -> IO () +runUrlPort port url app = do x <- newIORef True _ <- forkIO $ Warp.runSettings Warp.defaultSettings - { Warp.settingsPort = 4587 + { Warp.settingsPort = port , Warp.settingsOnException = const $ return () , Warp.settingsHost = "127.0.0.1" } $ ping x app - launch url + launch port url loop x loop :: IORef Bool -> IO () diff --git a/wai-handler-launch/wai-handler-launch.cabal b/wai-handler-launch/wai-handler-launch.cabal index c99ea4a3..f0d97d7c 100644 --- a/wai-handler-launch/wai-handler-launch.cabal +++ b/wai-handler-launch/wai-handler-launch.cabal @@ -1,5 +1,5 @@ Name: wai-handler-launch -Version: 0.0.4 +Version: 0.0.5 Synopsis: Launch a web app in the default browser. Description: This handles cross-platform launching and inserts Javascript code to ping the server. When the server no longer receives pings, it shuts down. License: BSD3