-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.fs
executable file
·38 lines (29 loc) · 1.23 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
open Suave
type CmdArgs = { IP: System.Net.IPAddress; Port: Sockets.Port }
[<EntryPoint>]
let main argv =
// parse arguments
let args =
let parse f str = match f str with (true, i) -> Some i | _ -> None
let (|Port|_|) = parse System.UInt16.TryParse
let (|IPAddress|_|) = parse System.Net.IPAddress.TryParse
//default bind to 127.0.0.1:8083
let defaultArgs = { IP = System.Net.IPAddress.Loopback; Port = 8083us }
let rec parseArgs b args =
match args with
| [] -> b
| "--ip" :: IPAddress ip :: xs -> parseArgs { b with IP = ip } xs
| "--port" :: Port p :: xs -> parseArgs { b with Port = p } xs
| invalidArgs ->
printfn "error: invalid arguments %A" invalidArgs
printfn "Usage:"
printfn " --ip ADDRESS ip address (Default: %O)" defaultArgs.IP
printfn " --port PORT port (Default: %i)" defaultArgs.Port
exit 1
argv |> List.ofArray |> parseArgs defaultArgs
// start suave
startWebServer
{ defaultConfig with
bindings = [ HttpBinding.create HTTP args.IP args.Port ] }
(Successful.OK "Hello World!")
0