Skip to content

Instantly share code, notes, and snippets.

@Krzysztof-Cieslak
Last active August 3, 2018 22:21
Show Gist options
  • Save Krzysztof-Cieslak/0018080f31ac43ed9e9050a72381973d to your computer and use it in GitHub Desktop.
Save Krzysztof-Cieslak/0018080f31ac43ed9e9050a72381973d to your computer and use it in GitHub Desktop.
Gists for "Using OAuth with Saturn" blog posts
module Router
open Saturn
open Giraffe.Core
open Giraffe.ResponseWriters
open Users
let browser = pipeline {
plug acceptHtml
plug putSecureBrowserHeaders
plug fetchSession
set_header "x-pipeline-type" "Browser"
}
let defaultView = router {
get "/" (htmlView Index.layout)
get "/index.html" (redirectTo false "/")
get "/default.html" (redirectTo false "/")
get "/signin-github" (redirectTo false "/members-only/")
}
let loggedInView = router {
pipe_through loggedIn
get "/" (htmlView UserPage.layout)
get "/admin" (isAdmin >=> htmlView AdminPage.layout)
}
let browserRouter = router {
not_found_handler (htmlView NotFound.layout) //Use the default 404 webpage
pipe_through browser //Use the default browser pipeline
forward "" defaultView //Use the default view
forward "/members-only" loggedInView
}
let appRouter = router {
forward "" browserRouter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment