Files
social-media/backend/Program.cs
Jonathan Bourdon df3e602015
Some checks failed
Backend CI/CD / build_and_deploy (push) Has been cancelled
Frontend CI/CD / build_and_deploy (push) Has been cancelled
feat: pivot to social media workflow app
2026-04-24 12:58:35 -04:00

128 lines
3.4 KiB
C#

using Azure.Identity;
using Socialize;
using Socialize.Data;
using Socialize.Infrastructure;
using Socialize.Infrastructure.Development;
using Socialize.Modules.Approvals;
using Socialize.Modules.Assets;
using Socialize.Modules.Clients;
using Socialize.Modules.Comments;
using Socialize.Modules.ContentItems;
using Socialize.Modules.Identity;
using Socialize.Modules.Notifications;
using Socialize.Modules.Projects;
using Socialize.Modules.Workspaces;
using Microsoft.AspNetCore.HttpOverrides;
using NSwag;
using NSwag.Generation.AspNetCore.Processors;
using NSwag.Generation.Processors.Security;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
if (!builder.Environment.IsDevelopment())
{
string? vaultUri = Environment.GetEnvironmentVariable("VaultUri");
if (vaultUri is null)
{
throw new InvalidOperationException("Missing VaultUri configuration setting");
}
builder.Configuration.AddAzureKeyVault(new Uri(vaultUri), new DefaultAzureCredential());
}
builder.Services.AddCors(options =>
{
options.AddPolicy(
"AllowAll",
policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// Add services to the container.
builder.Services.AddWebServices();
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);
builder.Services.AddOpenApiDocument((
configure,
_) =>
{
configure.Title = "Socialize API";
// Add JWT
configure.AddSecurity(
"JWT",
[],
new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.ApiKey,
Name = "Authorization",
In = OpenApiSecurityApiKeyLocation.Header,
Description = "Type into the textbox: Bearer {your JWT token}."
});
configure.OperationProcessors.Add(new AspNetCoreOperationTagsProcessor());
configure.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
});
string postgresConnectionString = builder.Configuration.GetConnectionString("PostgresConnection")
?? throw new InvalidOperationException(
"Missing ConnectionStrings:PostgresConnection");
builder.Services.AddFastEndpoints();
builder.Services.AddAppData(postgresConnectionString);
builder.AddInfrastructureModule();
builder.AddIdentityModule();
builder.AddWorkspaceModule();
builder.AddClientsModule();
builder.AddProjectsModule();
builder.AddContentItemsModule();
builder.AddAssetsModule();
builder.AddCommentsModule();
builder.AddApprovalsModule();
builder.AddNotificationsModule();
WebApplication app = builder.Build();
app.UseForwardedHeaders(
new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedProto }
);
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
// Initialize and seed the db.
await app.UseAppDataAsync();
await app.UseIdentityModuleAsync();
await app.UseDevelopmentSeedAsync();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHealthChecks("/health");
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
if (app.Environment.IsDevelopment())
{
app.UseOpenApi();
app.UseSwaggerUi(options => options.Path = "/api");
}
app.UseFastEndpoints();
app.Run();