Last active
October 16, 2016 21:30
-
-
Save zabirauf/5f8ff9faa0773a1e0ab84e34a4da19e1 to your computer and use it in GitHub Desktop.
A F# Suave web app that outputs HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SuaveBootstrapFlynn | |
open Suave | |
open Suave.Successful | |
open Suave.Web | |
open Suave.Operators | |
open Suave.Filters | |
open System | |
open System.Net | |
open System.Threading.Tasks | |
let helloWorld _ = | |
printfn "Saying hello world from F# and flynn %O" DateTime.UtcNow | |
OK (sprintf "<html><body><h1>Hello World - %O</h1></body></html>" DateTime.UtcNow) | |
let app = | |
GET >=> path "/" >=> request helloWorld | |
let config = | |
let port = System.Environment.GetEnvironmentVariable("PORT") | |
let ip127 = IPAddress.Parse("127.0.0.1") | |
let ipZero = IPAddress.Parse("0.0.0.0") | |
{ defaultConfig with | |
logger = Logging.Loggers.saneDefaultsFor Logging.LogLevel.Verbose | |
bindings=[ (if port = null then HttpBinding.mk HTTP ip127 (uint16 8080) | |
else HttpBinding.mk HTTP ipZero (uint16 port)) ] } | |
[<EntryPoint>] | |
let main argv = | |
startWebServer config 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