-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (43 loc) · 1.46 KB
/
Program.cs
File metadata and controls
50 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Text.Json.Serialization;
using Auth.Attributes;
using Auth.Database;
using Microsoft.AspNetCore.Mvc;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IConfigurationRoot conf = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.Development.json").Build();
JWTHandler.Secret = conf.GetValue<string>("JwtSecret");
builder.WebHost.UseUrls(conf.GetValue<string>("Host"));
builder.Services.AddControllers().AddJsonOptions(x=> x.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull);
builder.Services.AddSwaggerGen(opt =>
{
opt.ResolveConflictingActions(x=> x.LastOrDefault());
});
builder.Services.AddApiVersioning(x => x.AssumeDefaultVersionWhenUnspecified = true);
builder.Services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
builder.Services.AddScoped<RequireAuthAttribute>();
builder.Services.AddScoped<RequirePermissionAttribute>();
WebApplication app = builder.Build();
app.Use(JWTMiddleware.InvokeAsync);
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.UseCors(x =>
{
x.AllowAnyOrigin();
x.AllowAnyHeader();
x.AllowAnyMethod();
});
//handles 404
app.UseStatusCodePages(async (ctx) =>
{
if (ctx.HttpContext.Response.StatusCode != 404)
{
await ctx.Next(ctx.HttpContext);
return;
}
ctx.HttpContext.Response.Redirect("https://magicalmirai.com");
});
app.Run();