https://github.com/dazinator/blazor-sample-multi-spa
sample showing how to server different blaz spa's to different tenants as of blazor 3.2 preview 2 static files.
https://github.com/dazinator/blazor-sample-multi-spa
Last synced: about 2 months ago
JSON representation
sample showing how to server different blaz spa's to different tenants as of blazor 3.2 preview 2 static files.
- Host: GitHub
- URL: https://github.com/dazinator/blazor-sample-multi-spa
- Owner: dazinator
- Created: 2020-04-08T14:21:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-08T17:26:32.000Z (about 6 years ago)
- Last Synced: 2025-10-16T14:31:14.292Z (8 months ago)
- Language: C#
- Size: 229 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Blazor - Select different wasms to serve on different paths
This example shows multiple Blazor wasm projects referenced from the host, each client project
has it's own `StaticWebAssetBasePath` to prevent conflicts, e.g:
```
.private/spa2
```
Then the host, gets to serve the one it chooses, on the root url "/" thanks to some new extensions methods that I produced via taking a lot of the existing blazor extension methods and setup and tweaking it, and adding in a couple of helper extension methods "UseBlazorSpa"
Startup.cs:
```
// tenant A browse on port 5000
app.MapWhen((a) => a.Request.Host.Port == 5000,
(app) =>
{
var files = app.UseBlazorSpa("/", ".private/spa1", Configuration);
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html",
new StaticFileOptions() { FileProvider = files });
});
});
// tenant B browse on port 5001
app.MapWhen((a) => a.Request.Host.Port == 5001,
(app) =>
{
var files = app.UseBlazorSpa("/", ".private/spa2", Configuration);
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html",
new StaticFileOptions() { FileProvider = files });
});
});
```
`app.UseBlazorSpa` does the magic, and there are a couple of overloads, the one shown above creates the file provider to source the spa static files, and makes those files available on the path you choose - in this sample that is the root "/".
Note: see https://github.com/dotnet/aspnetcore/issues/20642 and https://github.com/dotnet/aspnetcore/issues/20605