Skip to content

Instantly share code, notes, and snippets.

@nojaf
Last active August 26, 2019 19:15
Show Gist options
  • Save nojaf/2af1aeed33ae96940ed64838eaf96acb to your computer and use it in GitHub Desktop.
Save nojaf/2af1aeed33ae96940ed64838eaf96acb to your computer and use it in GitHub Desktop.
Suave subPath
open System
open Suave
open Suave.Filters
let subPath path (ctx:HttpContext) =
async {
let localPath = ctx.request.url.LocalPath
let result =
match (localPath.StartsWith(path)) with
| false -> None
| true ->
let builder = UriBuilder(ctx.request.url)
builder.Path <- localPath.Substring(path.Length)
let newRequest = { ctx.request with url = builder.Uri}
{ ctx with request = newRequest}
|> Some
return result
}
(*
Example:
let app =
subPath "/v1" >=> choose [
path "/home" >=> Successful.OK "home"
path "/meh" >=> Successful.OK "meh"
]
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment