삽질하다 도저히 문제 파악이 안돼서 opcUaManager로 분리 테스트 중
This commit is contained in:
90
opcUaManager/Program.cs
Normal file
90
opcUaManager/Program.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using OpcUaManager.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// ── DI 등록 ───────────────────────────────────────────────────────────
|
||||
builder.Services.AddSingleton<OpcSessionService>();
|
||||
builder.Services.AddSingleton<CertService>();
|
||||
builder.Services.AddSingleton<OpcCrawlerService>();
|
||||
builder.Services.AddSingleton<DatabaseService>();
|
||||
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(opt =>
|
||||
{
|
||||
opt.JsonSerializerOptions.Converters.Add(
|
||||
new System.Text.Json.Serialization.JsonStringEnumConverter());
|
||||
opt.JsonSerializerOptions.PropertyNamingPolicy =
|
||||
System.Text.Json.JsonNamingPolicy.CamelCase;
|
||||
});
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(opt =>
|
||||
{
|
||||
opt.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
|
||||
{
|
||||
Title = "OPC UA Manager API",
|
||||
Version = "v1",
|
||||
Description = "OPC UA 클라이언트 인증서 생성 · 세션 관리 · 노드 탐색 · DB 저장"
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddCors(opt =>
|
||||
{
|
||||
opt.AddDefaultPolicy(policy =>
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod());
|
||||
});
|
||||
|
||||
// ── 앱 빌드 ───────────────────────────────────────────────────────────
|
||||
var app = builder.Build();
|
||||
|
||||
// ── 정적 파일: wwwroot 경로를 명시적으로 지정 ─────────────────────────
|
||||
// dotnet run 실행 위치와 무관하게 프로젝트 루트의 wwwroot 를 서빙
|
||||
var wwwrootPath = Path.Combine(
|
||||
builder.Environment.ContentRootPath, "wwwroot");
|
||||
|
||||
if (!Directory.Exists(wwwrootPath))
|
||||
{
|
||||
// dotnet run 이 프로젝트 루트가 아닌 곳에서 실행될 경우 대비
|
||||
wwwrootPath = Path.Combine(
|
||||
AppContext.BaseDirectory, "wwwroot");
|
||||
}
|
||||
|
||||
app.Logger.LogInformation("wwwroot 경로: {Path}", wwwrootPath);
|
||||
|
||||
app.UseDefaultFiles(new DefaultFilesOptions
|
||||
{
|
||||
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(wwwrootPath),
|
||||
RequestPath = ""
|
||||
});
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(wwwrootPath),
|
||||
RequestPath = ""
|
||||
});
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(opt =>
|
||||
{
|
||||
opt.SwaggerEndpoint("/swagger/v1/swagger.json", "OPC UA Manager v1");
|
||||
opt.RoutePrefix = "swagger";
|
||||
});
|
||||
|
||||
app.UseCors();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
// ── PKI 디렉토리 초기화 ───────────────────────────────────────────────
|
||||
foreach (var dir in new[]
|
||||
{
|
||||
"pki/own/certs", "pki/trusted/certs",
|
||||
"pki/issuers/certs", "pki/rejected/certs"
|
||||
})
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
app.Logger.LogInformation("=== OPC UA Manager 시작 ===");
|
||||
app.Logger.LogInformation("Frontend : http://localhost:5000/");
|
||||
app.Logger.LogInformation("Swagger : http://localhost:5000/swagger");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user