mirror of
https://github.com/CyberL1/MyMcRealms.git
synced 2024-11-14 10:28:21 -05:00
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
|
using Microsoft.EntityFrameworkCore;
|
||
|
using Minecraft_Realms_Emulator.Data;
|
||
|
using Minecraft_Realms_Emulator.Helpers;
|
||
|
using Minecraft_Realms_Emulator.Middlewares;
|
||
|
using Npgsql;
|
||
|
|
||
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
DotNetEnv.Env.Load();
|
||
|
|
||
|
if (Environment.GetEnvironmentVariable("CONNECTION_STRING") == null)
|
||
|
{
|
||
|
Console.WriteLine("CONNECTION_STRING environment variable missing");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Add services to the container.
|
||
|
|
||
|
builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles);
|
||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||
|
builder.Services.AddEndpointsApiExplorer();
|
||
|
builder.Services.AddSwaggerGen();
|
||
|
|
||
|
var dataSourceBuilder = new NpgsqlDataSourceBuilder(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
|
||
|
dataSourceBuilder.EnableDynamicJson();
|
||
|
var dataSource = dataSourceBuilder.Build();
|
||
|
|
||
|
builder.Services.AddDbContext<DataContext>(options =>
|
||
|
{
|
||
|
options.UseNpgsql(dataSource);
|
||
|
});
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
// Initialize database
|
||
|
Database.Initialize(app);
|
||
|
|
||
|
// Configure the HTTP request pipeline.
|
||
|
if (app.Environment.IsDevelopment())
|
||
|
{
|
||
|
app.UseSwagger();
|
||
|
app.UseSwaggerUI();
|
||
|
}
|
||
|
|
||
|
app.UseMiddleware<MinecraftCookieMiddleware>();
|
||
|
|
||
|
app.MapControllers();
|
||
|
|
||
|
app.Run();
|