@@ -4,6 +4,7 @@
44module Network.Wai.Handler.Launch
55 ( run
66 , runUrl
7+ , runUrlPort
78 ) where
89
910import Network.Wai
@@ -105,32 +106,35 @@ foreign import ccall "launch"
105106 launch' :: Int -> CString -> IO ()
106107#endif
107108
108−launch :: String -> IO ()
109+launch :: Int -> String -> IO ()
109110
110111#if WINDOWS
111−launch s = withCString s $ launch' 4587
112+launch port s = withCString s $ launch' port
112113#else
113−launch s = forkIO (rawSystem
114+launch port s = forkIO (rawSystem
114115#if MAC
115116 "open"
116117#else
117118 "xdg-open"
118119#endif
119− ["http://127.0.0.1:4587/" ++ s] >> return ()) >> return ()
120+ ["http://127.0.0.1:" ++ show port ++ "/" ++ s] >> return ()) >> return ()
120121#endif
121122
122123run :: Application -> IO ()
123124run = runUrl ""
124125
125126runUrl :: String -> Application -> IO ()
126−runUrl url app = do
127+runUrl = runUrlPort 4587
128+
129+runUrlPort :: Int -> String -> Application -> IO ()
130+runUrlPort port url app = do
127131 x <- newIORef True
128132 _ <- forkIO $ Warp.runSettings Warp.defaultSettings
129− { Warp.settingsPort = 4587
133+ { Warp.settingsPort = port
130134 , Warp.settingsOnException = const $ return ()
131135 , Warp.settingsHost = "127.0.0.1"
132136 } $ ping x app
133− launch url
137+ launch port url
134138 loop x
135139
136140loop :: IORef Bool -> IO ()