skantravels/API/Program.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2024-08-12 09:58:27 +01:00
using Microsoft.EntityFrameworkCore;
2024-08-05 08:00:16 +01:00
namespace API
{
public class Program
{
public static void Main(string[] args)
{
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options =>
{
options.AddPolicy(
name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("*").AllowAnyMethod().AllowAnyHeader();
}
);
});
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
2024-08-12 09:58:27 +01:00
IConfiguration Configuration = builder.Configuration;
var connectionString = Configuration.GetConnectionString("DefaultConnection") ?? Environment.GetEnvironmentVariable("DefaultConnection");
builder.Services.AddDbContext<AppDBContext>(options => options.UseSqlite(connectionString));
2024-08-05 08:00:16 +01:00
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseCors(MyAllowSpecificOrigins);
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}