From b2282969138c609d59849dbb001595e171796ca8 Mon Sep 17 00:00:00 2001 From: "seonkyu.kim" Date: Mon, 4 Nov 2024 14:46:04 +0900 Subject: [PATCH] =?UTF-8?q?[=E2=9C=A8]=20init=5FAPI=20GIT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Back.csproj | 16 ++++++++ Back.http | 6 +++ Program.cs | 73 ++++++++++++++++++++++++++++++++++ Properties/launchSettings.json | 41 +++++++++++++++++++ appsettings.Development.json | 8 ++++ appsettings.json | 9 +++++ 6 files changed, 153 insertions(+) create mode 100644 Back.csproj create mode 100644 Back.http create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 appsettings.Development.json create mode 100644 appsettings.json diff --git a/Back.csproj b/Back.csproj new file mode 100644 index 0000000..65e2d3e --- /dev/null +++ b/Back.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + false + + + + + + + + + diff --git a/Back.http b/Back.http new file mode 100644 index 0000000..ebc2035 --- /dev/null +++ b/Back.http @@ -0,0 +1,6 @@ +@Back_HostAddress = http://localhost:5144 + +GET {{Back_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..bce62c2 --- /dev/null +++ b/Program.cs @@ -0,0 +1,73 @@ +//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); +} \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..bce0946 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57683", + "sslPort": 44307 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5144", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7086;http://localhost:5144", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..ec04bc1 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file