Fix CORS in development
This commit is contained in:
@@ -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())
|
||||
{
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedOrigins": [
|
||||
"http://localhost:3000"
|
||||
],
|
||||
"NswFuelApiConfig": {
|
||||
"BaseUrl": "https://api.onegov.nsw.gov.au",
|
||||
"ApiKey": "1MYSRAx5yvqHUZc6VGtxix6oMA2qgfRT",
|
||||
|
||||
@@ -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(/\/+$/, "");
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user