Last active
June 9, 2020 14:37
-
-
Save dustinmoris/3951273c3e5a3f525127ebb072f359fd to your computer and use it in GitHub Desktop.
Isaac Problem
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
namespace GiraffeApp | |
open Microsoft.AspNetCore.Hosting | |
open Microsoft.AspNetCore.Builder | |
open Microsoft.Extensions.Hosting | |
open Giraffe | |
open System.Threading.Tasks | |
module Program = | |
let earlyReturn : HttpFunc = Some >> Task.FromResult | |
let authCheck : HttpHandler = | |
fun next ctx -> | |
let isValidAuth = | |
ctx.Request.Query.ContainsKey("apiKey") | |
&& ctx.Request.Query.["apiKey"].ToString() = "test123" | |
match isValidAuth with | |
| true -> next ctx | |
| false -> setStatusCode 401 earlyReturn ctx | |
let app : HttpHandler = | |
choose [ | |
authCheck >=> route "/api/foo" >=> text "foo" | |
authCheck >=> route "/api/bar" >=> text "bar" | |
] | |
let configureApp (appBuilder : IApplicationBuilder) = | |
appBuilder.UseGiraffe(app) | |
let StartWebServer args = | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(fun webBuilder -> | |
webBuilder.Configure(configureApp) |> ignore | |
) | |
.Build() | |
.Run() | |
0 | |
[<EntryPoint>] | |
let main args = StartWebServer args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment