mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-26 13:07:34 +00:00
Rewrite access tokens, initial admin api
This commit is contained in:
58
extra/admin-api/Spacebar.AdminAPI/Program.cs
Normal file
58
extra/admin-api/Spacebar.AdminAPI/Program.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Http.Timeouts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Spacebar.AdminAPI.Middleware;
|
||||
using Spacebar.Db.Contexts;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers(options => {
|
||||
options.MaxValidationDepth = null;
|
||||
options.MaxIAsyncEnumerableBufferLimit = 100;
|
||||
}).AddJsonOptions(options => {
|
||||
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
|
||||
options.JsonSerializerOptions.WriteIndented = true;
|
||||
});
|
||||
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddDbContextPool<SpacebarDbContext>(options => {
|
||||
options
|
||||
.UseNpgsql(builder.Configuration.GetConnectionString("Spacebar"))
|
||||
.EnableDetailedErrors();
|
||||
});
|
||||
|
||||
builder.Services.AddRequestTimeouts(x => {
|
||||
x.DefaultPolicy = new RequestTimeoutPolicy {
|
||||
Timeout = TimeSpan.FromMinutes(10),
|
||||
WriteTimeoutResponse = async context => {
|
||||
context.Response.StatusCode = 504;
|
||||
context.Response.ContentType = "application/json";
|
||||
await context.Response.StartAsync();
|
||||
await context.Response.WriteAsJsonAsync(new { error = "Unknown error" });
|
||||
await context.Response.CompleteAsync();
|
||||
}
|
||||
};
|
||||
});
|
||||
builder.Services.AddCors(options => {
|
||||
options.AddPolicy(
|
||||
"Open",
|
||||
policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors("Open");
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseMiddleware<AuthenticationMiddleware>();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user