Files
2024-06-21 16:29:31 +02:00

88 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
using Web3D.pack.Data;
var builder = WebApplication.CreateBuilder(args);
// configuration setup
Microsoft.Extensions.Configuration.ConfigurationManager configuration = builder.Configuration;
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
// NOTE: Add new mappings
provider.Mappings[".3mf"] = "model"; // NOTE: add the extension (with period) and its type
provider.Mappings[".3dm"] = "model"; // NOTE: add the extension (with period) and its type
// NOTE: comment this line of code out
// app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions // NOTE: replace the line app.UseStaticFiles(); with this block of code
{
ContentTypeProvider = provider
});
// gestione static files x modelli 3D: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-8.0
string path3mf = configuration.GetValue<string>("ServerConf:path3mf") ?? configuration.GetValue<string>("OptConf:path3mf") ?? "";
if (!string.IsNullOrEmpty(path3mf))
{
// verifico esista folder disegni
if (Directory.Exists(path3mf))
{
// gestione cartella x PDF
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(path3mf),
RequestPath = "/3mf",
ContentTypeProvider = provider
});
}
}
string path3dm = configuration.GetValue<string>("ServerConf:path3dm") ?? configuration.GetValue<string>("OptConf:path3dm") ?? "";
if (!string.IsNullOrEmpty(path3dm))
{
// verifico esista folder disegni
if (Directory.Exists(path3dm))
{
// gestione cartella x PDF
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(path3dm),
RequestPath = "/3dm",
ContentTypeProvider = provider
});
}
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();