Skip to content

Commit 9a97034

Browse files
committed
deployment and host config documentation
1 parent ce10731 commit 9a97034

File tree

5 files changed

+118
-13
lines changed

5 files changed

+118
-13
lines changed

documentation/authentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ let logOut : HttpHandler =
7676
Response.signOutAndRedirect authScheme redirectTo
7777
```
7878

79-
[Next: Example - Hello World](example-hello-world.md)
79+
[Next: Deployment](deployment.md)

documentation/deployment.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Deployment
2+
3+
One of the key features of Falco is that it contains little to no "magic" (i.e., no hidden reflection or dynamic code). This means that Falco is both [trimmable](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) and [AOT](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot) compatible out of the box.
4+
5+
This means that you can deploy your Falco application as a self-contained executable, or as a native AOT executable, with no additional configuration. A huge benefit of this is that you can deploy your Falco application to any environment, without having to worry about the underlying runtime or dependencies.
6+
7+
> Important! If you're in a __scale-to-zero__ hosting environment consider using a [ReadyToRun](https://learn.microsoft.com/en-us/dotnet/core/deploying/ready-to-run) deployment. This will ensure that your application will experience faster cold start times.
8+
9+
## Self-contained deployments
10+
11+
It is highly recommended to deploy your Falco application as a self-contained executable. This means that the .NET runtime and all dependencies are included in the deployment package, so you don't have to worry about the target environment having the correct version of .NET installed. This will result in a slightly larger deployment package, but it will ensure that your application runs correctly in any environment. The larger binary size can also be offset by using trim.
12+
13+
Below is an example [Directory.Build.props] that will help enable the non-AOT features. These properties can also be added to you fsproj file.
14+
15+
```xml
16+
<Project>
17+
<PropertyGroup>
18+
<SelfContained>true</SelfContained>
19+
<PublishSingleFile>true</PublishSingleFile>
20+
<PublishTrimmed>true</PublishTrimmed>
21+
<TrimMode>Link</TrimMode>
22+
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
23+
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
24+
<!-- Optional: enable if in scale-to-zero hosting environment -->
25+
<!-- <PublishReadyToRun>true</PublishReadyToRun> -->
26+
</PropertyGroup>
27+
</Project>
28+
```
29+
30+
## Native AOT deployments
31+
32+
Publishing your app as Native AOT produces an app that's self-contained and that has been ahead-of-time (AOT) compiled to native code. Native AOT apps have faster startup time and smaller memory footprints. These apps can run on machines that don't have the .NET runtime installed.
33+
34+
Since AOT deployments require trimming, and are single file by nature the only required msbuild property is:
35+
36+
```xml
37+
<Project>
38+
<PropertyGroup>
39+
<PublishAot>true</PublishAot>
40+
</PropertyGroup>
41+
</Project>
42+
```
43+
44+
[Next: Example - Hello World](example-hello-world.md)

documentation/get-started.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ let wapp = WebApplication.Create()
5050
wapp.UseRouting()
5151
.UseFalco(endpoints)
5252
// ^-- activate Falco endpoint source
53-
.Run()
53+
.Run(Response.ofPlainText "Not found")
54+
// ^-- run app and register terminal (i.e., not found) middleware
5455
```
5556

5657
Run the application:
@@ -61,8 +62,4 @@ Run the application:
6162

6263
And there you have it, an industrial-strength [Hello World](https://github.com/pimbrouwers/Falco/tree/master/examples/HelloWorld) web app. Pretty sweet!
6364

64-
## Sample Applications
65-
66-
Code is worth a thousand words. For the most up-to-date usage, the [examples](https://github.com/pimbrouwers/Falco/tree/master/examples/) directory contains a few sample applications.
67-
68-
[Next: Routing](routing.md)
65+
[Next: Host Configuration](host-configuration.md)

documentation/host-configuration.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Host Configuration
2+
3+
As your app becomes more complex, you'll inevitably need to reach for some additional host configuration. This is where `Microsoft.AspNetCore.Builder` comes in, which contains many useful extensions for configuring the server (ex: static files, authentication, authorization etc.).
4+
5+
Most of the extension methods have existed since the early days of ASP.NET Core and operate against `IApplicationBuilder`. But more recent version of ASP.NET Core have introduced a new `WebApplication` type that implements `IApplicationBuilder` and provides some additional functionality, most notably endpoint configuration. This dichotomy makes pipelining next to impossible. In C# you don't feel the sting of this as much because of `void` returns. But in F# this results in an excess amount of `|> ignore` calls.
6+
7+
Let's take the hero code from the [Getting Started](get-started.md) page and add some static file middleware to it:
8+
9+
```fsharp
10+
module Program
11+
12+
open Falco
13+
open Falco.Routing
14+
open Microsoft.AspNetCore.Builder
15+
16+
let wapp = WebApplication.Create()
17+
18+
wapp.UseRouting()
19+
.UseDefaultFiles() // you might innocently think this is fine
20+
.UseStaticFiles() // and so is this
21+
// but uknowingly, the underlying type has changed
22+
.UseFalco([
23+
get "/" (Response.ofPlainText "Hello World!")
24+
])
25+
.Run(Response.ofPlainText "Not found")
26+
// ^-- this is no longer starts up our application
27+
28+
// one way to fix this:
29+
wapp.UseRouting() |> ignore
30+
wapp.UseDefaultFiles().UseStaticFiles() |> ignore
31+
32+
wapp.UseFalco([
33+
get "/" (Response.ofPlainText "Hello World!")
34+
])
35+
.Run(Response.ofPlainText "Not found")
36+
37+
// but we can do better
38+
```
39+
40+
To salve this, Falco comes with a several shims. The most important of these are `WebApplication.Use` and `WebApplication.UseIf` which allow you to compose a pipeline entirely driven by `WebApplication` while at the same time taking advantage of the existing ASP.NET Core extensions.
41+
42+
The optional, but recommended way to take advantage of these is to utilize the static methods that server as the underpinning to the various extension methods available. The code below will attempt to highlight this more clearly:
43+
44+
```fsharp
45+
// consider
46+
wapp.UseRouting()
47+
.Use(fun (appl : IApplicationBuilder) ->
48+
appl.UseDefaultFiles()
49+
.UseStaticFiles())
50+
.UseFalco([
51+
get "/" (Response.ofPlainText "Hello World!")
52+
])
53+
.Run(Response.ofPlainText "Not found")
54+
55+
// or better yet
56+
wapp.UseRouting()
57+
.Use(DefaultFilesExtensions.UseDefaultFiles)
58+
.Use(StaticFileExtensions.UseStaticFiles)
59+
// ^-- most IApplicationBuilder extensions are available as static methods similar to this
60+
.UseFalco([
61+
get "/" (Response.ofPlainText "Hello World!")
62+
])
63+
.Run(Response.ofPlainText "Not found")
64+
```
65+
66+
[Next: Routing](routing.md)

documentation/readme.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
---
2-
title: Welcome to Falco's documentation
3-
---
1+
# Welcome to Falco's Documentation
42

5-
# Documentation
6-
7-
Welcome to Falco's documentation, visit the [getting started](get-started.md) page for installation and a brief overview. There are also more detailed [examples](example-hello-world.md) that shows how to create a small but complete application with Falco. The rest of the docs describe each component of Falco in detail.
3+
Visit the [getting started](get-started.md) page for installation and a brief overview. There are also more detailed [examples](example-hello-world.md) that shows how to create a small but complete application with Falco. The rest of the docs describe each component of Falco in detail.
84

95
## Guides
106

117
Falco depends only on the high-performance base components of .NET and ASP.NET Core, and provides a toolset to build a working full-stack web application. This section of the documentation explains the different parts of Falco and how they can be used, customized, and extended. Beyond Falco itself, look for community-maintained extensions to add even more functionality.
128

139
- [Getting Started](get-started.md)
10+
- [Host Configuration](host-configuration.md)
1411
- [Routing](routing.md)
1512
- [Writing responses](response.md)
1613
- [Accessing request data](request.md)
1714
- [View engine](markup.md)
1815
- [Security](authentication.md)
16+
- [Deployment](deployment.md)
1917
- [Examples](example-hello-world.md)

0 commit comments

Comments
 (0)