Last active
August 26, 2019 19:15
-
-
Save nojaf/2af1aeed33ae96940ed64838eaf96acb to your computer and use it in GitHub Desktop.
Suave subPath
This file contains hidden or 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
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