This repository was archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (51 loc) · 1.73 KB
/
Program.cs
File metadata and controls
60 lines (51 loc) · 1.73 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
51
52
53
54
55
56
57
58
59
60
using System;
using System.Net;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Serialization;
using vault;
using vault.commons;
using vault.controllers;
using vault.exceptions;
var builder = WebApplication.CreateBuilder(args)
.WithWebHost(x =>
x.UseUrls($"http://*.*.*.*:{Environment.GetEnvironmentVariable("PORT") ?? "8080"}"));
builder.Services
.AddWebApi()
.AddScoped<IStoreAdapter, FireStoreAdapter>()
.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "Console Vault", Version = "v1" });
c.EnableAnnotations();
})
.AddSwaggerGenNewtonsoftSupport()
.AddRouting(options => options.LowercaseUrls = true);
var app = builder.Build();
app.UseMiddleware<CloudflareMiddleware>();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseSwagger();
app.UseAuthentication();
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Console Vault v1"));
app.UseExceptionHandler(x => x.Run(context =>
{
var exception = context.Features
.Get<IExceptionHandlerPathFeature>()?
.Error;
context.Response.StatusCode = 200;
if (exception is SpaceNotFoundException or AppNotFoundException or FieldNotFoundException)
context.Response.StatusCode = 404;
else
context.Response.StatusCode = 500;
return context.Response.WriteAsJsonAsync(new { message = exception?.Message });
}));
app.Run();