initialising for ci-cd pipeline
CI/CD - ERP Core / scripts (pull_request) Failing after 12m21s
CI/CD - ERP Core / e2e-typecheck (pull_request) Failing after 13m13s
CI/CD - ERP Core / frontend (pull_request) Failing after 14m5s
CI/CD - ERP Core / backend (pull_request) Failing after 14m57s
CI/CD - ERP Core / detect (pull_request) Failing after 13m42s
CI/CD - ERP Core / Build & Deploy (pull_request) Failing after 12m47s
CI/CD - ERP Core / ci-ok (pull_request) Failing after 14m58s
CI/CD - ERP Core / scripts (pull_request) Failing after 12m21s
CI/CD - ERP Core / e2e-typecheck (pull_request) Failing after 13m13s
CI/CD - ERP Core / frontend (pull_request) Failing after 14m5s
CI/CD - ERP Core / backend (pull_request) Failing after 14m57s
CI/CD - ERP Core / detect (pull_request) Failing after 13m42s
CI/CD - ERP Core / Build & Deploy (pull_request) Failing after 12m47s
CI/CD - ERP Core / ci-ok (pull_request) Failing after 14m58s
This commit is contained in:
@@ -15,6 +15,7 @@ using ERPCore.Services.Production;
|
||||
using ERPCore.Services.Stock;
|
||||
using ERPCore.System.Errors;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.OpenApi;
|
||||
@@ -23,10 +24,32 @@ using Serilog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Serilog (file sink) — reads levels from configuration, plus a rolling daily file.
|
||||
// Fail fast on missing deployment config. Outside Development these arrive as environment
|
||||
// variables (docs/40-DEPLOYMENT.md §5); a blank value would otherwise surface later as an
|
||||
// unrelated crash (e.g. `new Uri("")` for AuthHex:BaseUrl) instead of naming the key.
|
||||
if (!builder.Environment.IsDevelopment())
|
||||
{
|
||||
string[] requiredKeys =
|
||||
[
|
||||
"ConnectionStrings:DefaultConnection",
|
||||
"AuthHex:BaseUrl",
|
||||
"GeneralLedgerService:BaseUrl",
|
||||
"GeneralLedgerService:ApiKey",
|
||||
"Auth:RsaPublicKeyXml",
|
||||
];
|
||||
var missing = requiredKeys.Where(k => string.IsNullOrWhiteSpace(builder.Configuration[k])).ToArray();
|
||||
if (missing.Length > 0)
|
||||
throw new InvalidOperationException(
|
||||
$"Missing required configuration for environment '{builder.Environment.EnvironmentName}': " +
|
||||
$"{string.Join(", ", missing)}. Set them as environment variables (':' becomes '__', " +
|
||||
"e.g. ConnectionStrings__DefaultConnection).");
|
||||
}
|
||||
|
||||
// Serilog (file sink) — reads levels from configuration, plus a rolling daily file. The path is
|
||||
// configurable so deployed instances log outside their release folder (LogFile:Path).
|
||||
builder.Host.UseSerilog((ctx, cfg) => cfg
|
||||
.ReadFrom.Configuration(ctx.Configuration)
|
||||
.WriteTo.File("logs/erpcore-.log", rollingInterval: RollingInterval.Day));
|
||||
.WriteTo.File(ctx.Configuration["LogFile:Path"] ?? "logs/erpcore-.log", rollingInterval: RollingInterval.Day));
|
||||
|
||||
// Controllers + JSON: serialize enums as their string names (docs/11 §8, camelCase).
|
||||
builder.Services.AddControllers()
|
||||
@@ -49,8 +72,10 @@ builder.Services.AddErpJwtAuth(builder.Configuration);
|
||||
// AuthController proxy → AuthHex (docs/11 §2.0)
|
||||
builder.Services.AddHttpClient<IAuthHexClient, AuthHexClient>(c =>
|
||||
{
|
||||
var baseUrl = builder.Configuration["AuthHex:BaseUrl"]
|
||||
?? throw new InvalidOperationException("AuthHex:BaseUrl is not configured.");
|
||||
// Blank counts as missing: the base appsettings.json ships these keys empty on purpose.
|
||||
var baseUrl = builder.Configuration["AuthHex:BaseUrl"];
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
throw new InvalidOperationException("AuthHex:BaseUrl is not configured (set it in appsettings.Development.json locally).");
|
||||
c.BaseAddress = new Uri(baseUrl);
|
||||
});
|
||||
builder.Services.AddScoped<IAuthUserService, AuthUserService>();
|
||||
@@ -60,8 +85,9 @@ builder.Services.AddScoped<IAuthAltService, AuthAltService>();
|
||||
// General Ledger service proxy → external GL microservice (docs/12-GENERAL-LEDGER-INTEGRATION.md)
|
||||
builder.Services.AddHttpClient<IGeneralLedgerClient, GeneralLedgerClient>(c =>
|
||||
{
|
||||
var baseUrl = builder.Configuration["GeneralLedgerService:BaseUrl"]
|
||||
?? throw new InvalidOperationException("GeneralLedgerService:BaseUrl is not configured.");
|
||||
var baseUrl = builder.Configuration["GeneralLedgerService:BaseUrl"];
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
throw new InvalidOperationException("GeneralLedgerService:BaseUrl is not configured (set it in appsettings.Development.json locally).");
|
||||
c.BaseAddress = new Uri(baseUrl);
|
||||
});
|
||||
builder.Services.AddScoped<IGeneralLedgerService, GeneralLedgerService>();
|
||||
@@ -205,7 +231,10 @@ using (var scope = app.Services.CreateScope())
|
||||
await db.Database.MigrateAsync();
|
||||
try
|
||||
{
|
||||
await DataSeeder.SeedAsync(db);
|
||||
// Demo rows (sample catalog, stock, customers, sales docs) default on only in Development;
|
||||
// the test deployment opts in with Seed__DemoData=true, release never does.
|
||||
var includeDemoData = app.Configuration.GetValue("Seed:DemoData", app.Environment.IsDevelopment());
|
||||
await DataSeeder.SeedAsync(db, includeDemoData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -213,9 +242,18 @@ using (var scope = app.Services.CreateScope())
|
||||
}
|
||||
}
|
||||
|
||||
// Behind the co-located Apache reverse proxy (docs/40-DEPLOYMENT.md): take the client IP and
|
||||
// scheme from X-Forwarded-*. Only loopback proxies are trusted by default, which is exactly it.
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
app.UseSerilogRequestLogging();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
// Off in Production only. The test deployment (Staging) keeps it; it is still not public there
|
||||
// because Apache proxies only /api/ — reach it through an SSH tunnel to the backend port.
|
||||
if (!app.Environment.IsProduction())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
Reference in New Issue
Block a user