Created
November 22, 2017 17:21
-
-
Save ctaggart/f919607252c0cedeb79b0f75023e72c0 to your computer and use it in GitHub Desktop.
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 App | |
open Node | |
open Node.http2 | |
open Node.net | |
open Fable.Core | |
open Fable.Core.JsInterop | |
let noObj: obj option = None | |
let server = http2.createSecureServer(jsOptions<SecureServerOptions>(fun opt -> | |
opt.key <- fs.readFileSync(PathLike.ofString "localhost-privkey.pem" |> U2.Case1, noObj) |> U4.Case3 |> Some | |
opt.cert <- fs.readFileSync(PathLike.ofString "localhost-cert.pem" |> U2.Case1, noObj) |> U4.Case3 |> Some | |
)) | |
server.on_error (fun err -> printfn "%A" err) |> ignore | |
server.on_socketError (fun err -> printfn "%A" err) |> ignore | |
server.on_stream (fun stream _inHeaders _ -> | |
let outHeaders = createEmpty<OutgoingHttpHeaders> | |
outHeaders.["content-type"] <- "text/html" |> U3.Case2 |> Some | |
outHeaders.[":status"] <- 200. |> U3.Case1 |> Some | |
stream.respond outHeaders | |
let wstream = stream :> stream.Writable | |
wstream.``end``("<h1>HTTP/2 from F# !!!</h1>", "utf8") | |
) |> ignore | |
server.listen(jsOptions<ListenOptions>(fun opt -> | |
opt.port <- 8443. |> Some | |
)) |> ignore |
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
dotnet new -i ctaggart.templates | |
dotnet new http2 -n myhttp2 | |
cd myhttp2 | |
.\build.ps1 | |
.\localhost-cert.ps1 | |
.\start.ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
!^
to instantiate erased unions. Not everybody likes it, but it makes the code less verbose and removes the need to specify the case while keeping type checking: