@@ -4,6 +4,7 @@
44module Network.Wai.Handler.Launch
55 ( run
66 , runUrl
7+ , runUrlPort
78 ) where
89
910import Network.Wai
@@ -125,32 +126,35 @@ foreign import ccall "launch"
125126 launch' :: Int -> CString -> IO ()
126127#endif
127128
128−launch :: String -> IO ()
129+launch :: Int -> String -> IO ()
129130
130131#if WINDOWS
131−launch s = withCString s $ launch' 4587
132+launch port s = withCString s $ launch' port
132133#else
133−launch s = forkIO (rawSystem
134+launch port s = forkIO (rawSystem
134135#if MAC
135136 "open"
136137#else
137138 "xdg-open"
138139#endif
139− ["http://127.0.0.1:4587/" ++ s] >> return ()) >> return ()
140+ ["http://127.0.0.1:" ++ show port ++ "/" ++ s] >> return ()) >> return ()
140141#endif
141142
142143run :: Application -> IO ()
143144run = runUrl ""
144145
145146runUrl :: String -> Application -> IO ()
146−runUrl url app = do
147+runUrl = runUrlPort 4587
148+
149+runUrlPort :: Int -> String -> Application -> IO ()
150+runUrlPort port url app = do
147151 x <- newIORef True
148152 _ <- forkIO $ Warp.runSettings Warp.defaultSettings
149− { Warp.settingsPort = 4587
153+ { Warp.settingsPort = port
150154 , Warp.settingsOnException = const $ return ()
151155 , Warp.settingsHost = "127.0.0.1"
152156 } $ ping x app
153− launch url
157+ launch port url
154158 loop x
155159
156160loop :: IORef Bool -> IO ()