Skip to content

Instantly share code, notes, and snippets.

@lmatt-bit
Created August 4, 2016 07:27
Show Gist options
  • Save lmatt-bit/dce5e181206db9eb9ce6b74603643526 to your computer and use it in GitHub Desktop.
Save lmatt-bit/dce5e181206db9eb9ce6b74603643526 to your computer and use it in GitHub Desktop.
FSharp Script TO Run Local Http Server
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open Suave
open Suave.Filters
open Suave.Operators
open Suave.Successful
open Suave.Sockets
open System.Net
let mkMimeType name compression =
{ name=name; compression=compression } |> Some
let app =
choose[
GET >=> choose
[
path "/test.bin" >=> Files.file "test.bin"
path "/test" >=> OK "Hello Test"
]
POST >=> choose
[
path "/test.bin" >=> Files.file "test.bin"
]
]
let defaultMimeTypesMap = function
| ".bin" -> mkMimeType "application/octet-stream" false
| _ -> None
[<EntryPoint>]
let main argv =
let socketBinding = {ip = IPAddress.Any; port = uint16 84}
let binding = {scheme = Protocol.HTTP; socketBinding = socketBinding}
let bindings = [|binding|] |> Array.toList
let webConfig = {defaultConfig with mimeTypesMap = defaultMimeTypesMap; bindings = bindings}
startWebServer webConfig app
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment