73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
//var builder = WebApplication.CreateBuilder(args);
|
|
/*
|
|
var options = new WebApplicationOptions
|
|
{
|
|
WebRootPath = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"
|
|
? "/src/publish/Debug/wwwroot"
|
|
: "/src/publish/Release/wwwroot"
|
|
};
|
|
*/
|
|
|
|
// var currentDirectory = Directory.GetCurrentDirectory();
|
|
// var webRootPath = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"
|
|
// ? Path.Combine(currentDirectory, "publish/Debug/wwwroot")
|
|
// : Path.Combine(currentDirectory, "publish/Release/wwwroot");
|
|
|
|
var webRootPath = Environment.GetEnvironmentVariable("ASPNETCORE_WEBROOT");
|
|
// builder.WebHost.UseWebRoot(webRootPath);
|
|
|
|
var options = new WebApplicationOptions { WebRootPath = webRootPath };
|
|
|
|
var builder = WebApplication.CreateBuilder(options);
|
|
|
|
// var env = builder.Environment.EnvironmentName;
|
|
// string wwwrootPath = env == "Development" ? "/src/publish/Debug/wwwroot" : "/src/publish/Release/wwwroot";
|
|
// builder.WebHost.UseWebRoot(wwwrootPath);
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
// .UseStaticFiles()
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
ServeUnknownFileTypes = true
|
|
});
|
|
app.UseRouting();
|
|
app.MapFallbackToFile("index.html");
|
|
|
|
var summaries = new[]
|
|
{
|
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
};
|
|
|
|
app.MapGet("/weatherforecast", () =>
|
|
{
|
|
var forecast = Enumerable.Range(1, 5).Select(index =>
|
|
new WeatherForecast
|
|
(
|
|
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
Random.Shared.Next(-20, 55),
|
|
summaries[Random.Shared.Next(summaries.Length)]
|
|
))
|
|
.ToArray();
|
|
return forecast;
|
|
})
|
|
.WithName("GetWeatherForecast")
|
|
.WithOpenApi();
|
|
|
|
app.Run();
|
|
|
|
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
|
{
|
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
} |