Created
April 20, 2025 19:14
-
-
Save Aaronontheweb/dd67dcc45d97fe081d43f9d872be9e74 to your computer and use it in GitHub Desktop.
Falco Static Files
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
module Program | |
open Falco | |
open Falco.Routing | |
open Microsoft.AspNetCore.Builder | |
let wapp = WebApplication.Create() | |
wapp.UseRouting() | |
.UseDefaultFiles() | |
.UseStaticFiles() | |
.UseFalco([ | |
]) | |
.Run(Response.ofPlainText "Not found") |
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
module Program | |
open Falco | |
open Falco.Routing | |
open Microsoft.AspNetCore.Builder | |
let wapp = WebApplication.Create() | |
wapp.UseRouting() | |
.UseDefaultFiles() | |
.UseStaticFiles() | |
.Run(Response.ofPlainText "Not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for chiming in Stuart with a solution.
Both program files fall through because they are hitting an ASP.NET extension, Microsoft.AspNetCore.Builder.RunExtensions.Run, which adds a terminal middleware to the pipeline. This has a dramatically different effect than Microsoft.AspNetCore.Builder.WebApplication.Run which runs the application and blocks the calling thread. The latter is not being called here in either example, so the host never starts up.
A lot of the older extension methods like
UseStaticFiles()
andUseDefaultFiles()
are hung offIApplicationBuilder
, where the endpoint methods are hung off WebApplication. The dichotomy makes pipelining the builder next to impossible. In C# you don't feel the sting of this as much because ofvoid
returns. To salve this, Falco comes with a couple shims to avoid an incessant amount of|> ignore
calls. In both examples you actually use one,UseRouting()
(required to activate Falco which depends on ASP.NET endpoints).The most important of these are
WebApplication.Use
andWebApplication.UseIf
which allow you to compose a pipeline entirely driven byWebApplication
. Throughout the documentation I point out that theopen Microsoft.AspNetCore.Builder
import adds many useful extensions, many of these are complete unknown to most devs, but are the underpinning to the builder extension method. They are a bit esoteric, but they are really useful in F#-land. A quick example:The HelloWorldMVC example shows how to use this effectively.