2023-12-29 04:19:18 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
namespace Mirea.Api.Endpoint;
|
|
|
|
|
|
|
|
public class Program
|
|
|
|
{
|
2024-01-26 19:30:41 +03:00
|
|
|
private static IConfigurationRoot ConfigureEnvironment()
|
|
|
|
{
|
|
|
|
EnvironmentManager.LoadEnvironment(".env");
|
|
|
|
var environmentVariables = Environment.GetEnvironmentVariables()
|
|
|
|
.OfType<DictionaryEntry>()
|
|
|
|
.ToDictionary(
|
|
|
|
entry => entry.Key.ToString() ?? string.Empty,
|
|
|
|
entry => entry.Value?.ToString() ?? string.Empty
|
|
|
|
);
|
|
|
|
|
|
|
|
var result = new ConfigurationBuilder().AddInMemoryCollection(environmentVariables!);
|
|
|
|
|
|
|
|
return result.Build();
|
|
|
|
}
|
|
|
|
|
2023-12-29 04:19:18 +03:00
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2024-01-26 19:31:28 +03:00
|
|
|
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
|
|
|
|
|
2023-12-29 04:19:18 +03:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2024-01-26 19:30:41 +03:00
|
|
|
builder.Configuration.AddConfiguration(ConfigureEnvironment());
|
|
|
|
builder.Configuration.AddJsonFile(Settings.FilePath, optional: true, reloadOnChange: true);
|
2023-12-29 04:19:18 +03:00
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
2024-01-26 19:32:10 +03:00
|
|
|
|
|
|
|
builder.Services.AddCors(options =>
|
|
|
|
{
|
|
|
|
options.AddPolicy("AllowAll", policy =>
|
|
|
|
{
|
|
|
|
policy.AllowAnyHeader();
|
|
|
|
policy.AllowAnyMethod();
|
|
|
|
policy.AllowAnyOrigin();
|
|
|
|
});
|
|
|
|
});
|
2023-12-29 04:19:18 +03:00
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
app.Run();
|
|
|
|
}
|
|
|
|
}
|