[✨] Front 연결 #1
|
|
@ -1,7 +1,13 @@
|
|||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||
{
|
||||
WebRootPath = Environment.GetEnvironmentVariable("ASPNETCORE_WEBROOT")
|
||||
?? "wwwroot"
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
|
@ -11,31 +17,23 @@ if (app.Environment.IsDevelopment())
|
|||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
var webRoot = app.Environment.WebRootPath;
|
||||
Console.WriteLine($"[System] Web Root Path: {webRoot}"); // 로그에 경로 찍어보기
|
||||
|
||||
if (Directory.Exists(webRoot))
|
||||
{
|
||||
app.UseStaticFiles(); // 경로가 있으면 파일 서빙
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("[Error] Web root folder not found!");
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseRouting();
|
||||
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
// [4] 요청 처리
|
||||
app.MapControllers();
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
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");
|
||||
|
||||
app.Run();
|
||||
|
||||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
||||
{
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
app.Run();
|
||||
Loading…
Reference in New Issue
Block a user