+26
-2
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Serilog;
|
||||
using System.Reflection;
|
||||
using System.Threading.RateLimiting;
|
||||
using Refit;
|
||||
|
||||
|
||||
// Load .env file if it exists (for local development)
|
||||
@@ -80,11 +81,34 @@ try
|
||||
builder.Services.AddHttpClient<ICaptchaVerifier, RecaptchaVerifier>();
|
||||
builder.Services.AddSingleton<IEmailSender, SmtpEmailSender>();
|
||||
builder.Services.AddSingleton<Microsoft.AspNetCore.StaticFiles.IContentTypeProvider, Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider>();
|
||||
builder.Services.AddHttpClient("CvMatcherApi");
|
||||
|
||||
// Refit client for CvMatcher API
|
||||
builder.Services.AddRefitClient<Api.Clients.Api.Contracts.ICvMatcherApi>()
|
||||
.ConfigureHttpClient((sp, client) =>
|
||||
{
|
||||
var config = sp.GetRequiredService<IConfiguration>();
|
||||
var baseUrl = config["CvMatcherApi:BaseUrl"] ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(baseUrl)) client.BaseAddress = new Uri(baseUrl.TrimEnd('/') + "/");
|
||||
|
||||
var key = config["CvMatcherApi:InternalApiKey"];
|
||||
if (!string.IsNullOrWhiteSpace(key) && !client.DefaultRequestHeaders.Contains("X-Internal-Api-Key"))
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("X-Internal-Api-Key", key);
|
||||
}
|
||||
});
|
||||
|
||||
// Swagger
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
// Include XML comments (enable <GenerateDocumentationFile> in csproj)
|
||||
var xmlFile = (Assembly.GetExecutingAssembly().GetName().Name ?? "Api") + ".xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
if (File.Exists(xmlPath)) options.IncludeXmlComments(xmlPath);
|
||||
|
||||
// Enable annotations like [SwaggerOperation], [SwaggerResponse]
|
||||
options.EnableAnnotations();
|
||||
});
|
||||
|
||||
// If you're behind Caddy / reverse proxy
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
|
||||
Reference in New Issue
Block a user