Fix CORS
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
namespace ALttPRandomizer.Options {
|
namespace ALttPRandomizer.Options {
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class ServiceOptions {
|
public class ServiceOptions {
|
||||||
public string Baserom { get; set; } = null!;
|
public string Baserom { get; set; } = null!;
|
||||||
public string PythonPath { get; set; } = null!;
|
public string PythonPath { get; set; } = null!;
|
||||||
public string RandomizerPath { get; set; } = null!;
|
public string RandomizerPath { get; set; } = null!;
|
||||||
|
public IList<string> AllowedCors { get; set; } = new List<string>();
|
||||||
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
|
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,22 @@
|
|||||||
|
|
||||||
builder.Services.AddLogging(lb => lb.AddConsole());
|
builder.Services.AddLogging(lb => lb.AddConsole());
|
||||||
|
|
||||||
|
var provider = builder.Services.BuildServiceProvider();
|
||||||
|
var settings = provider.GetRequiredService<IOptionsMonitor<ServiceOptions>>().CurrentValue!;
|
||||||
|
var logger = provider.GetRequiredService<ILogger<Program>>();
|
||||||
|
|
||||||
|
builder.Services.AddCors(options => {
|
||||||
|
options.AddPolicy("AllowDomains", policy => {
|
||||||
|
foreach (var domain in settings.AllowedCors) {
|
||||||
|
policy.WithOrigins(domain);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddControllers().AddJsonOptions(x =>
|
builder.Services.AddControllers().AddJsonOptions(x =>
|
||||||
x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
var provider = builder.Services.BuildServiceProvider();
|
|
||||||
var settings = provider.GetRequiredService<IOptionsMonitor<ServiceOptions>>().CurrentValue!;
|
|
||||||
|
|
||||||
var options = new DefaultAzureCredentialOptions();
|
var options = new DefaultAzureCredentialOptions();
|
||||||
|
|
||||||
if (settings.AzureSettings.ClientId != null) {
|
if (settings.AzureSettings.ClientId != null) {
|
||||||
@@ -53,6 +62,7 @@
|
|||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
app.UseCors("AllowDomains");
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(c => {
|
app.UseSwaggerUI(c => {
|
||||||
|
|||||||
Reference in New Issue
Block a user