Skip to content

Commit 702816f

Browse files
committed
Add missing V4 documentation
1 parent 50f885d commit 702816f

5 files changed

Lines changed: 111 additions & 6 deletions

File tree

astro/src/content/docs/bff/fundamentals/apis/local.mdx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,32 @@ public class SampleApiController : ControllerBase
215215

216216
:::note
217217
It's also possible to disable anti-forgery protection using _BffOptions.DisableAntiForgeryCheck()_
218-
:::
218+
:::
219+
220+
### Skipping Response Handling
221+
222+
By default, when BFF pre/post-processing is enabled on an endpoint (via `.AsBffApiEndpoint()`), the BFF framework
223+
intercepts authentication challenge and forbid responses. Instead of returning a 302 redirect to the identity provider
224+
(which is not useful for API calls), it converts them to API-friendly status codes:
225+
226+
- **Challenge** (unauthenticated) → returns **401** (instead of 302 redirect)
227+
- **Forbid** (unauthorized) → returns **403** (instead of 302 redirect)
228+
229+
If you want to opt out of this behavior and let the default authentication response handling occur (e.g., if your
230+
endpoint needs to trigger a redirect), you can use the `SkipResponseHandling()` extension method:
231+
232+
```csharp
233+
app.MapGet("/my-endpoint", context => { /* ... */ })
234+
.AsBffApiEndpoint()
235+
.SkipResponseHandling();
236+
```
237+
238+
For MVC controllers, you can use the `[BffApiSkipResponseHandling]` attribute:
239+
240+
```csharp
241+
[Route("my-endpoint")]
242+
[BffApi]
243+
[BffApiSkipResponseHandling]
244+
public class MyController : ControllerBase
245+
{ /* ... */ }
246+
```

astro/src/content/docs/bff/fundamentals/multi-frontend/index.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,34 @@ var frontend = new BffFrontend(BffFrontendName.Parse("frontend1"))
184184
When you do this, the BFF automatically wires up a catch-all route that serves the `index.html` for that specific frontend.
185185
See [Serve the index page from the BFF host](/bff/architecture/ui-hosting.md#serve-the-index-page-from-the-bff-host) for more information.
186186

187+
#### Transforming the `index.html`
188+
189+
If you need to modify the `index.html` before it is served to the client (for example, to inject frontend-specific
190+
configuration or environment variables), you can implement the `IIndexHtmlTransformer` interface:
191+
192+
```csharp
193+
public class MyIndexHtmlTransformer : IIndexHtmlTransformer
194+
{
195+
public Task<string?> Transform(string indexHtml, BffFrontend frontend, CancellationToken ct = default)
196+
{
197+
// Inject a frontend-specific config script tag
198+
var transformed = indexHtml.Replace(
199+
"</head>",
200+
$"<script>window.__CONFIG__ = {{ frontend: '{frontend.Name}' }};</script></head>");
201+
return Task.FromResult<string?>(transformed);
202+
}
203+
}
204+
```
205+
206+
Register the transformer in the service collection:
207+
208+
```csharp
209+
services.AddSingleton<IIndexHtmlTransformer, MyIndexHtmlTransformer>();
210+
```
211+
212+
The transformer is called after the `index.html` is fetched from the CDN and before it is cached. The cache duration
213+
is controlled by the [`IndexHtmlDefaultCacheDuration`](/bff/fundamentals/options.md#cdn--static-assets) option.
214+
187215
### Proxying All Static Assets
188216

189217
When developing a Single-Page Application (SPA), it's very common to use a development webserver such as Vite. While Vite can publish static assets with a base URL, this doesn't work well during development.

astro/src/content/docs/bff/fundamentals/options.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,41 @@ builder.Services.AddBff(options =>
4848

4949
* ***AutomaticallyRegisterBffMiddleware*** (added in 4.0)
5050

51-
When applying BFF V4 multiple frontends, a lot of middlewares get automatically added to the pipeline. For example, the frontend selection middleware, the authentication handlers, etc. If you don't want this automatic behavior, then you can turn it off and register these middlewares manually.
51+
When using BFF V4 with multiple frontends, several middlewares are automatically added to the pipeline (frontend
52+
selection, path mapping, OpenID Connect callbacks, management endpoints, and static file proxying). If you need
53+
full control over the middleware pipeline, set this to `false` and register the middleware manually:
54+
55+
```csharp
56+
builder.Services.AddBff(options =>
57+
{
58+
options.AutomaticallyRegisterBffMiddleware = false;
59+
});
60+
```
61+
62+
When disabled, you must call `UseBffPreProcessing()` early in the pipeline (before authentication) and
63+
`UseBffPostProcessing()` at the end:
64+
65+
```csharp
66+
app.UseForwardedHeaders();
67+
app.UseBffPreProcessing(); // Frontend selection, path mapping, OpenID callbacks
68+
69+
app.UseAuthentication();
70+
app.UseRouting();
71+
app.UseBff(); // Anti-forgery checks
72+
app.UseAuthorization();
73+
74+
// map your endpoints here...
75+
76+
app.UseBffPostProcessing(); // Management endpoints, remote API handling, static file proxying
77+
```
78+
79+
You can also use the individual middleware methods for even more granular control:
80+
81+
* `UseBffFrontendSelection()` — Selects the current frontend based on host/path matching
82+
* `UseBffPathMapping()` — Adjusts `PathBase` and `Path` for the selected frontend
83+
* `UseBffOpenIdCallbacks()` — Handles OpenID Connect callback requests
84+
* `UseBffAntiForgery()` — Validates anti-forgery headers (same as `UseBff()`)
85+
* `UseBffStaticFileProxying()` — Proxies static file requests to CDN or development server
5286

5387

5488
* ***StaticAssetsClientName***
@@ -151,6 +185,21 @@ builder.Services.AddBff(options =>
151185
* ***DisableAntiForgeryCheck*** (added in V4)
152186
A delegate that determines if the anti-forgery check should be disabled for a given request. The default is not to disable anti-forgery checks.
153187

188+
## CDN / Static Assets
189+
190+
* ***IndexHtmlDefaultCacheDuration*** (added in V4)
191+
192+
If you use CDN Index HTML proxying (via `BffFrontend.CdnIndexHtmlUrl`), this controls how long the fetched `index.html` is cached. Defaults to *5 minutes*.
193+
194+
## Diagnostics
195+
196+
* ***Diagnostics*** (added in V4)
197+
198+
Options that control the way that diagnostic data is logged. This is a nested options object with the following properties:
199+
200+
* ***LogFrequency***Frequency at which diagnostic summaries are logged. Defaults to *1 hour*.
201+
* ***ChunkSize***Max size of diagnostic data log message chunks in bytes. Defaults to *8160 bytes* (8 KB minus 32 bytes for log message formatting overhead).
202+
154203

155204
# BFF Blazor Server Options
156205

astro/src/content/docs/bff/fundamentals/session/management/user.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ To use the endpoint, make an HTTP GET request to it from your frontend javascrip
9595
could use the fetch API to make requests to the user endpoint like this:
9696

9797
```js title="session.js"
98-
var req = new Request("/user", {
98+
var req = new Request("/bff/user", {
9999
headers: new Headers({
100100
"X-CSRF": "1",
101101
}),
@@ -135,7 +135,7 @@ activity. To prevent the call to the user endpoint from sliding the cookie, add
135135
request.
136136

137137
```js title="site.js"
138-
var req = new Request("/user?slide=false", {
138+
var req = new Request("/bff/user?slide=false", {
139139
headers: new Headers({
140140
"X-CSRF": "1",
141141
}),

astro/src/content/docs/bff/getting-started/blazor.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To configure the server, the first step is to add the BFF Blazor package.
3838

3939
```shell
4040
cd BlazorBffApp
41-
dotnet add package Duende.BFF.Blazor --version 3.0.0
41+
dotnet add package Duende.BFF.Blazor
4242
```
4343

4444
Then you need to configure the application to use the BFF Blazor application. Add this to your services:
@@ -171,7 +171,7 @@ To add the BFF to the client project, add the following:
171171
```shell
172172
cd ..
173173
cd BlazorBffApp.Client
174-
dotnet add package Duende.BFF.Blazor.Client --version 3.0.0
174+
dotnet add package Duende.BFF.Blazor.Client
175175
```
176176

177177
Then add the following to your program.cs:

0 commit comments

Comments
 (0)