wip
This commit is contained in:
@@ -1,79 +1,60 @@
|
||||
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 FastEndpoints;
|
||||
using FastEndpoints.Swagger;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using NSwag;
|
||||
using NSwag.Generation.AspNetCore.Processors;
|
||||
using NSwag.Generation.Processors.Security;
|
||||
using Socialize;
|
||||
using Socialize.Api.Infrastructure;
|
||||
using Socialize.Api.Infrastructure.Development;
|
||||
using Socialize.Api.Modules.Approvals;
|
||||
using Socialize.Api.Modules.Assets;
|
||||
using Socialize.Api.Modules.Clients;
|
||||
using Socialize.Api.Modules.Comments;
|
||||
using Socialize.Api.Modules.ContentItems;
|
||||
using Socialize.Api.Modules.Identity;
|
||||
using Socialize.Api.Modules.Notifications;
|
||||
using Socialize.Api.Modules.Projects;
|
||||
using Socialize.Api.Modules.Workspaces;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
if (!builder.Environment.IsDevelopment())
|
||||
{
|
||||
string? vaultUri = Environment.GetEnvironmentVariable("VaultUri");
|
||||
|
||||
if (vaultUri is null)
|
||||
{
|
||||
throw new InvalidOperationException("Missing VaultUri configuration setting");
|
||||
}
|
||||
var vaultUri = Environment.GetEnvironmentVariable("VaultUri") ?? 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();
|
||||
});
|
||||
});
|
||||
.AllowAnyHeader()
|
||||
)
|
||||
);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddWebServices();
|
||||
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);
|
||||
|
||||
builder.Services.AddOpenApiDocument((
|
||||
configure,
|
||||
_) =>
|
||||
builder.Services.AddFastEndpoints();
|
||||
builder.Services.SwaggerDocument(o =>
|
||||
{
|
||||
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"));
|
||||
o.EnableGetRequestsWithBody = false;
|
||||
o.EnableJWTBearerAuth = true;
|
||||
o.DocumentSettings = s =>
|
||||
{
|
||||
s.Title = "Socialize API";
|
||||
s.Version = "v1";
|
||||
};
|
||||
});
|
||||
|
||||
string postgresConnectionString = builder.Configuration.GetConnectionString("PostgresConnection")
|
||||
var postgresConnectionString = builder.Configuration.GetConnectionString("PostgresConnection")
|
||||
?? throw new InvalidOperationException(
|
||||
"Missing ConnectionStrings:PostgresConnection");
|
||||
|
||||
builder.Services.AddFastEndpoints();
|
||||
builder.Services.AddAppData(postgresConnectionString);
|
||||
builder.AddInfrastructureModule();
|
||||
builder.AddIdentityModule();
|
||||
@@ -86,7 +67,7 @@ builder.AddCommentsModule();
|
||||
builder.AddApprovalsModule();
|
||||
builder.AddNotificationsModule();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseForwardedHeaders(
|
||||
new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedProto }
|
||||
@@ -116,12 +97,7 @@ if (!app.Environment.IsDevelopment())
|
||||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseOpenApi();
|
||||
app.UseSwaggerUi(options => options.Path = "/api");
|
||||
}
|
||||
|
||||
app.UseFastEndpoints();
|
||||
app.UseSwaggerGen();
|
||||
|
||||
app.Run();
|
||||
await app.RunAsync();
|
||||
|
||||
Reference in New Issue
Block a user