30
Program.cs
30
Program.cs
@@ -1,8 +1,3 @@
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using System.IO;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
@@ -13,36 +8,11 @@ app.MapGet("/api/test", () => "test works!");
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// No need for UseHttpsRedirection or UseHsts, as Nginx handles SSL.
|
||||
|
||||
app.UseDefaultFiles(); // Enable default file serving
|
||||
app.UseStaticFiles(); // Serve static files from wwwroot
|
||||
|
||||
// Add MIME types for WebAssembly files
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
provider.Mappings[".wasm"] = "application/wasm";
|
||||
provider.Mappings[".dat"] = "application/octet-stream";
|
||||
|
||||
// Serve Blazor WebAssembly files from /batterij-simulator
|
||||
// This must be registered after the default static files but before routing
|
||||
app.Map("/batterij-simulator", appBuilder =>
|
||||
{
|
||||
var options = new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(
|
||||
Path.Combine(builder.Environment.ContentRootPath, "wwwroot", "batterij-simulator")),
|
||||
RequestPath = string.Empty, // Serve from the root of the /batterij-simulator path
|
||||
ContentTypeProvider = provider
|
||||
};
|
||||
appBuilder.UseStaticFiles(options);
|
||||
appBuilder.UseDefaultFiles(); // Enable default file serving for the subpath
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers(); // Map API controllers
|
||||
|
||||
// Fallback for Blazor WebAssembly to serve index.html for any subpath
|
||||
app.MapFallbackToFile("/batterij-simulator/{*path:nonfile}", "/batterij-simulator/index.html");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user