Fix CORS in development
This commit is contained in:
@@ -28,21 +28,18 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(c => c.EnableAnnotations());
|
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()
|
||||||
policy.WithOrigins(allowedOrigins ?? [])
|
.AllowAnyMethod();
|
||||||
.AllowAnyHeader()
|
|
||||||
.AllowAnyMethod();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@@ -63,13 +60,13 @@ app.UseSwaggerUI();
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseRateLimiter();
|
app.UseRateLimiter();
|
||||||
|
app.UseCors();
|
||||||
|
|
||||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
||||||
{
|
{
|
||||||
Authorization = [new NoAuthFilter()]
|
Authorization = [new NoAuthFilter()]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isDevelopment) app.UseCors();
|
|
||||||
|
|
||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"AllowedOrigins": [
|
||||||
|
"http://localhost:3000"
|
||||||
|
],
|
||||||
"NswFuelApiConfig": {
|
"NswFuelApiConfig": {
|
||||||
"BaseUrl": "https://api.onegov.nsw.gov.au",
|
"BaseUrl": "https://api.onegov.nsw.gov.au",
|
||||||
"ApiKey": "1MYSRAx5yvqHUZc6VGtxix6oMA2qgfRT",
|
"ApiKey": "1MYSRAx5yvqHUZc6VGtxix6oMA2qgfRT",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import type { Configuration } from './configuration';
|
|||||||
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
|
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
|
||||||
import globalAxios 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