Initial commit - ECommerce project
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using Commerce.Config;
|
||||
using Commerce.Endpoints;
|
||||
using Commerce.Contracts.Options;
|
||||
using Commerce.Domain;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
Npgsql.NpgsqlConnection.GlobalTypeMapper.EnableDynamicJson();
|
||||
#pragma warning restore CS0618
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
// builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.Configure<JWT>(builder.Configuration.GetSection("JWT"));
|
||||
|
||||
// builder.Services.AddDbContext<Context>(
|
||||
// options => options.(builder.Configuration["ConnectionStrings:maria"], ServerVersion.AutoDetect(builder.Configuration["ConnectionStrings:maria"])));
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("PostgreDB");
|
||||
var dataSourceBuilder = new Npgsql.NpgsqlDataSourceBuilder(connectionString);
|
||||
dataSourceBuilder.EnableDynamicJson();
|
||||
var dataSource = dataSourceBuilder.Build();
|
||||
|
||||
builder.Services.AddDbContext<Context>(options =>
|
||||
options.UseNpgsql(dataSource)
|
||||
);
|
||||
|
||||
|
||||
// builder.Services.AddCustomCors();
|
||||
|
||||
builder.Services.RegFluentEmail(builder.Configuration);
|
||||
builder.Services.AddCustomCors();
|
||||
builder.Services.AddSwag();
|
||||
builder.Services.Authenticate(builder.Configuration);
|
||||
|
||||
builder.Services.Authorize();
|
||||
builder.Services.RegisterServices();
|
||||
|
||||
// builder.Services.AddAntiforgery();
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = 512 * 1024 * 1024; // 512 MB
|
||||
});
|
||||
|
||||
// Configure form options for multipart body length
|
||||
builder.Services.Configure<FormOptions>(options =>
|
||||
{
|
||||
options.MultipartBodyLengthLimit = 512 * 1024 * 1024; // 512 MB
|
||||
});
|
||||
|
||||
// builder.WebHost.UseUrls("http://*:80"); // Explicit HTTP binding
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<Context>();
|
||||
db.Database.Migrate(); // Applies pending migrations
|
||||
}
|
||||
|
||||
// if (args.Contains("--migrate"))
|
||||
// {
|
||||
// using var scope = app.Services.CreateScope();
|
||||
// var db = scope.ServiceProvider.GetRequiredService<Context>();
|
||||
// db.Database.Migrate();
|
||||
// }
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseCors("default");
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// if (app.Environment.IsDevelopment())
|
||||
// {
|
||||
// app.UseSwagger();
|
||||
// app.UseSwaggerUI();
|
||||
// }
|
||||
|
||||
// app.UseAntiforgery();
|
||||
|
||||
// app.UseHttpsRedirection();
|
||||
app.MapOpenApi();
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwag();
|
||||
}
|
||||
app.MapAPIv1();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user