Fix CORS in development

This commit is contained in:
kurt-mcrae
2024-11-24 19:05:28 +11:00
parent 3a17d45a97
commit 09ad091ad6
3 changed files with 14 additions and 14 deletions

View File

@@ -28,21 +28,18 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c => c.EnableAnnotations());
if (!isDevelopment)
{
var allowedOrigins = Environment.GetEnvironmentVariable("ALLOWED_ORIGINS")?.Split(',') ??
configuration.GetSection("AllowedOrigins").Get<string[]>();
var allowedOrigins = Environment.GetEnvironmentVariable("ALLOWED_ORIGINS")?.Split(',') ??
configuration.GetSection("AllowedOrigins").Get<string[]>();
builder.Services.AddCors(options =>
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins(allowedOrigins ?? [])
.AllowAnyHeader()
.AllowAnyMethod();
});
policy.WithOrigins(allowedOrigins ?? [])
.AllowAnyHeader()
.AllowAnyMethod();
});
}
});
var app = builder.Build();
@@ -63,13 +60,13 @@ app.UseSwaggerUI();
app.UseHttpsRedirection();
app.MapControllers();
app.UseRateLimiter();
app.UseCors();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = [new NoAuthFilter()]
});
if (!isDevelopment) app.UseCors();
using (var scope = app.Services.CreateScope())
{

View File

@@ -5,6 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedOrigins": [
"http://localhost:3000"
],
"NswFuelApiConfig": {
"BaseUrl": "https://api.onegov.nsw.gov.au",
"ApiKey": "1MYSRAx5yvqHUZc6VGtxix6oMA2qgfRT",

View File

@@ -19,7 +19,7 @@ import type { Configuration } from './configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
export const BASE_PATH = "http://localhost:5000".replace(/\/+$/, "");
export const BASE_PATH = "http://localhost:5161".replace(/\/+$/, "");
/**
*