1
0
mirror of https://github.com/CyberL1/MyMcRealms.git synced 2024-11-13 18:08:23 -05:00
MyMcRealms/Minecraft-Realms-Emulator/Program.cs
2024-04-20 09:20:30 +02:00

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();