Fetching contributors…
Cannot retrieve contributors at this time
38 lines (31 sloc) 1.14 KB
/// Functions for managing the Suave web server.
module ServerCode.WebServer
open ServerCode
open ServerCode.ServerUrls
open Giraffe
open Giraffe.TokenRouter
open RequestErrors
open Microsoft.AspNetCore.Http
/// Start the web server and connect to database
let webApp databaseType =
let startupTime = System.DateTime.UtcNow
let db = Database.getDatabase databaseType startupTime
let apiPathPrefix = PathString("/api")
let notfound: HttpHandler =
fun next ctx ->
if ctx.Request.Path.StartsWithSegments(apiPathPrefix) then
NOT_FOUND "Page not found" next ctx
Pages.notfound next ctx
router notfound [
route PageUrls.Home Pages.home
route PageUrls.Login Pages.login
route APIUrls.WishList (Auth.requiresJwtTokenForAPI (WishList.getWishList db.LoadWishList))
route APIUrls.ResetTime (WishList.getResetTime db.GetLastResetTime)
route APIUrls.Login Auth.login
route APIUrls.WishList (Auth.requiresJwtTokenForAPI (WishList.postWishList db.SaveWishList))