using Microsoft.Extensions.DependencyInjection.Extensions;



var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(builder =>
                      {
						  
						
						 

						  /*
						  builder
						 .WithOrigins("https://*.bremen.com.tw", 
							"https://localhost:7245", 
							"https://bremen.com.tw")
						 .AllowAnyMethod()
						 .AllowAnyHeader();
						  */
						  
						   builder
						  .WithOrigins(GlobalClass.appsettings("CorsOrigins")
						  .Split(",", StringSplitOptions.RemoveEmptyEntries)
						  .ToArray() ?? Array.Empty<string>())
						  .SetIsOriginAllowedToAllowWildcardSubdomains()
						  .AllowAnyMethod()
						  .AllowAnyHeader(); 
						  

					  });
});

// Add services to the container.
builder.Services.AddControllersWithViews();

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
defaultFilesOptions.DefaultFileNames.Clear();
defaultFilesOptions.DefaultFileNames.Add("index.html");
defaultFilesOptions.DefaultFileNames.Add("iisstart.htm");
app.UseDefaultFiles(defaultFilesOptions);
app.UseCors();
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
