| | 1 | | using CrossCutting.CommonDependenceInject; |
| | 2 | | using Despesas.Application.CommonDependenceInject; |
| | 3 | | using Despesas.Backend.CommonDependenceInject; |
| | 4 | | using Despesas.Infrastructure.CommonDependenceInject; |
| | 5 | | using Microsoft.EntityFrameworkCore; |
| | 6 | | using Repository; |
| | 7 | | using Repository.CommonDependenceInject; |
| | 8 | | using Despesas.GlobalException.CommonDependenceInject; |
| | 9 | |
|
| 0 | 10 | | var builder = WebApplication.CreateBuilder(args); |
| | 11 | |
|
| | 12 | | // Add Cors Configurations |
| 0 | 13 | | builder.Services.AddCors(options => |
| 0 | 14 | | { |
| 0 | 15 | | options.AddDefaultPolicy(policy => |
| 0 | 16 | | { |
| 0 | 17 | | policy.WithOrigins( |
| 0 | 18 | | "https://alexfariakof.com", |
| 0 | 19 | | "https://alexfariakof.com:42535", |
| 0 | 20 | | "https://localhost", |
| 0 | 21 | | "https://localhost:42535", |
| 0 | 22 | | "https://localhost:4200", |
| 0 | 23 | | "https://127.0.0.1", |
| 0 | 24 | | "https://127.0.0.1:4200", |
| 0 | 25 | | "https://127.0.0.1:42535", |
| 0 | 26 | | "https://accounts.google.com") |
| 0 | 27 | | .AllowAnyMethod() |
| 0 | 28 | | .AllowAnyHeader() |
| 0 | 29 | | .AllowCredentials(); |
| 0 | 30 | | }); |
| 0 | 31 | | }); |
| | 32 | |
|
| 0 | 33 | | builder.Services.AddRouting(options => options.LowercaseUrls = true); |
| 0 | 34 | | builder.Services.AddControllers(); |
| 0 | 35 | | builder.Services.AddSwaggerApiVersioning(); |
| | 36 | |
|
| | 37 | |
|
| 0 | 38 | | if (builder.Environment.IsStaging() || builder.Environment.IsDevelopment()) |
| 0 | 39 | | { |
| 0 | 40 | | builder.Services.AddDbContext<RegisterContext>(options => options |
| 0 | 41 | | .UseLazyLoadingProxies() |
| 0 | 42 | | .UseMySQL(builder.Configuration.GetConnectionString("Dev.SqlConnectionString") ?? |
| 0 | 43 | | throw new NullReferenceException("SqlConnectionString not defined."))); |
| 0 | 44 | | } |
| | 45 | | else |
| 0 | 46 | | { |
| 0 | 47 | | builder.Services.AddDbContext<RegisterContext>(options => options |
| 0 | 48 | | .UseMySQL(builder.Configuration.GetConnectionString("SqlConnectionString") ?? |
| 0 | 49 | | throw new NullReferenceException("SqlConnectionString not defined."))); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | //Add SigningConfigurations |
| 0 | 53 | | builder.AddSigningConfigurations(); |
| | 54 | |
|
| | 55 | | // Add AuthConfigurations |
| 0 | 56 | | builder.AddAuthenticationConfigurations(); |
| | 57 | |
|
| | 58 | | // Add Cryptography Configurations |
| 0 | 59 | | builder.Services.AddServicesCryptography(builder.Configuration); |
| | 60 | |
|
| | 61 | | // Add CommonDependencesInject |
| 0 | 62 | | builder.Services.AddAutoMapper(); |
| 0 | 63 | | builder.Services.AddAmazonS3BucketConfigurations(builder.Configuration); |
| 0 | 64 | | builder.Services.AddRepositories(); |
| 0 | 65 | | builder.Services.AddServices(); |
| 0 | 66 | | builder.Services.AddCrossCuttingConfiguration(); |
| | 67 | |
|
| 0 | 68 | | if (builder.Environment.IsStaging()) |
| 0 | 69 | | { |
| 0 | 70 | | builder.WebHost.UseUrls("https://0.0.0.0:42535", "http://0.0.0.0:42536"); |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | // remove todos os providers (Console, Debug, EventLog etc.) Mata Kubernetes |
| 0 | 74 | | if (builder.Environment.IsProduction() || builder.Environment.IsStaging()) |
| 0 | 75 | | builder.Logging.ClearProviders(); |
| | 76 | |
|
| 0 | 77 | | var app = builder.Build(); |
| | 78 | |
|
| | 79 | | //Configure Global Execeptions |
| 0 | 80 | | app.UseGlobalExceptionHandler(); |
| | 81 | |
|
| | 82 | | // Configure the HTTP request pipeline |
| 0 | 83 | | app.UseHsts(); |
| | 84 | |
|
| 0 | 85 | | app.UseHttpsRedirection(); |
| 0 | 86 | | app.AddSupporteCulturesPtBr(); |
| 0 | 87 | | app.UseCors(); |
| 0 | 88 | | app.AddSwaggerUIApiVersioning(); |
| 0 | 89 | | app.UseDefaultFiles(); |
| 0 | 90 | | app.UseStaticFiles(); |
| 0 | 91 | | app.UseRouting(); |
| 0 | 92 | | app.UseCertificateForwarding(); |
| 0 | 93 | | app.UseAuthentication(); |
| 0 | 94 | | app.UseAuthorization(); |
| | 95 | |
|
| 0 | 96 | | app.MapControllers(); |
| 0 | 97 | | app.MapFallbackToFile("index.html"); |
| | 98 | |
|
| 0 | 99 | | if (app.Environment.IsStaging()) |
| 0 | 100 | | { |
| 0 | 101 | | app.Urls.Add("https://0.0.0.0:42535"); |
| 0 | 102 | | app.Urls.Add("http://0.0.0.0:42536"); |
| 0 | 103 | | } |
| | 104 | |
|
| 0 | 105 | | app.Run(); |