ExperionCrawler First Commit
This commit is contained in:
63
src/Web/Program.cs
Normal file
63
src/Web/Program.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using ExperionCrawler.Core.Application.Interfaces;
|
||||
using ExperionCrawler.Core.Application.Services;
|
||||
using ExperionCrawler.Infrastructure.Certificates;
|
||||
using ExperionCrawler.Infrastructure.Csv;
|
||||
using ExperionCrawler.Infrastructure.Database;
|
||||
using ExperionCrawler.Infrastructure.OpcUa;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// ── MVC / Swagger ─────────────────────────────────────────────────────────────
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
c.SwaggerDoc("v1", new() { Title = "ExperionCrawler API", Version = "v1" }));
|
||||
|
||||
// ── Infrastructure ────────────────────────────────────────────────────────────
|
||||
builder.Services.AddSingleton<IExperionCertificateService, ExperionCertificateService>();
|
||||
builder.Services.AddSingleton<IExperionStatusCodeService, ExperionStatusCodeService>();
|
||||
builder.Services.AddScoped<IExperionOpcClient, ExperionOpcClient>();
|
||||
builder.Services.AddScoped<IExperionCsvService, ExperionCsvService>();
|
||||
builder.Services.AddScoped<AssetLoader>();
|
||||
|
||||
// PostgreSQL – Ubuntu 서버에서 별도 설치 없이 동작
|
||||
Directory.CreateDirectory("data");
|
||||
builder.Services.AddDbContext<ExperionDbContext>(opt =>
|
||||
opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
builder.Services.AddScoped<IExperionDbService, ExperionDbService>();
|
||||
|
||||
// ── Application Services ──────────────────────────────────────────────────────
|
||||
builder.Services.AddScoped<ExperionCrawlService>();
|
||||
|
||||
// ── CORS ──────────────────────────────────────────────────────────────────────
|
||||
builder.Services.AddCors(opt =>
|
||||
opt.AddDefaultPolicy(p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
|
||||
|
||||
// ── 포트 설정 (Ubuntu 환경: 기본 5000) ───────────────────────────────────────
|
||||
builder.WebHost.UseUrls("http://0.0.0.0:5000");
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// ── DB 초기화 ─────────────────────────────────────────────────────────────────
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<IExperionDbService>();
|
||||
await db.InitializeAsync();
|
||||
}
|
||||
|
||||
// ── Middleware ────────────────────────────────────────────────────────────────
|
||||
app.UseCors();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseDefaultFiles(); // index.html
|
||||
app.UseStaticFiles(); // wwwroot/
|
||||
app.MapControllers();
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user