38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Net;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text.Json;
|
|
using VideoArchiveAPI;
|
|
|
|
string configPath = "config.json";
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// configPath 를 현재 실행 파일이 있는 폴더로 변경
|
|
configPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), configPath);
|
|
|
|
if (!System.IO.File.Exists(configPath))
|
|
{
|
|
string defaultSetting = "{\"Config\": {\"Port\": 8981,\"Location\": \".\\\\\"}}";
|
|
System.IO.File.WriteAllText(configPath , defaultSetting);
|
|
|
|
|
|
}
|
|
|
|
builder.Configuration.AddJsonFile(configPath, optional: false, reloadOnChange: true);
|
|
builder.Services.Configure<Config>(builder.Configuration.GetSection("Config"));
|
|
Config localConfig = builder.Configuration.GetSection(Config.SectionName).Get<Config>();
|
|
|
|
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
|
|
{
|
|
serverOptions.Listen(IPAddress.Loopback, localConfig.Port);
|
|
});
|
|
|
|
builder.Services.AddControllers();
|
|
var app = builder.Build();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|