Last active
November 29, 2020 22:44
-
-
Save samueleaton/b2ed07ede6a6bc6cf45f98e53a32f664 to your computer and use it in GitHub Desktop.
simple hello world server in F#
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 MyApp | |
open Sol.Context | |
module Middlewares = | |
let authenticateAdmin next ctx = | |
let isAdmin = hasQueryParam "is_admin" ctx | |
if isAdmin then | |
next ctx | |
else | |
ctx |> setStatusCode 403 |> writeText "Access Denied" | |
module Handlers = | |
let getHome ctx = | |
ctx |> write "welcome home..." | |
let getArtist ctx = | |
let artistId = getRouteParam "artist_id" ctx | |
ctx |> writeText $"got artist: {artistId}" | |
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
// App Entry | |
namespace MyApp | |
module Program = | |
open Sol.Server | |
[<EntryPoint>] | |
let main args = | |
genServer() | |
|> setPort 3007 | |
|> setRoutes Routes.routes | |
|> run | |
0 |
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 MyApp | |
module Routes = | |
open Middlewares | |
open Handlers | |
open Sol.Route | |
let routes = [ | |
// run authentication and them getHome if successful | |
get "/" (authenticateAdmin <| getHome); | |
get "/admin/{artist_id}" getArtist | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment