Merge branch 'Feature_Task_management' of https://git.marcoaiot.com/admin/marco.pms.api into Feature_Task_management
This commit is contained in:
commit
15e83346e2
@ -10,7 +10,6 @@ using MarcoBMS.Services.Helpers;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace MarcoBMS.Services.Controllers
|
namespace MarcoBMS.Services.Controllers
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ using System.Text;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|
||||||
// Add Serilog Configuration
|
// Add Serilog Configuration
|
||||||
builder.Host.UseSerilog((context, config) =>
|
builder.Host.UseSerilog((context, config) =>
|
||||||
{
|
{
|
||||||
@ -24,34 +23,49 @@ builder.Host.UseSerilog((context, config) =>
|
|||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
#region CORS Settings
|
||||||
|
|
||||||
// Add services
|
// Add services
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("DevCorsPolicy", policy =>
|
||||||
|
{
|
||||||
|
policy.AllowAnyOrigin()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//var corsSettings = builder.Configuration.GetSection("Cors");
|
||||||
|
//var allowedOrigins = corsSettings.GetValue<string>("AllowedOrigins")?.Split(',');
|
||||||
|
//var allowedMethods = corsSettings.GetValue<string>("AllowedMethods")?.Split(',');
|
||||||
|
//var allowedHeaders = corsSettings.GetValue<string>("AllowedHeaders")?.Split(',');
|
||||||
|
|
||||||
//builder.Services.AddCors(options =>
|
//builder.Services.AddCors(options =>
|
||||||
//{
|
//{
|
||||||
// options.AddPolicy("DevCorsPolicy", policy =>
|
// options.AddPolicy("Policy", policy =>
|
||||||
// {
|
// {
|
||||||
// policy.AllowAnyOrigin()
|
// if (allowedOrigins != null)
|
||||||
// .AllowAnyMethod()
|
// {
|
||||||
// .AllowAnyHeader();
|
// policy.WithOrigins(allowedOrigins)
|
||||||
|
// .WithMethods(allowedMethods)
|
||||||
|
// .WithHeaders(allowedHeaders);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// options.AddPolicy("AllowAll", policy =>
|
||||||
|
// {
|
||||||
|
// if (allowedOrigins != null)
|
||||||
|
// {
|
||||||
|
// policy.AllowAnyOrigin()
|
||||||
|
// .AllowAnyMethod()
|
||||||
|
// .AllowAnyHeader();
|
||||||
|
|
||||||
|
// }
|
||||||
// });
|
// });
|
||||||
//});
|
//});
|
||||||
|
|
||||||
var corsSettings = builder.Configuration.GetSection("Cors");
|
#endregion
|
||||||
var allowedOrigins = corsSettings.GetValue<string>("AllowedOrigins")?.Split(',');
|
|
||||||
var allowedMethods = corsSettings.GetValue<string>("AllowedMethods")?.Split(',');
|
|
||||||
var allowedHeaders = corsSettings.GetValue<string>("AllowedHeaders")?.Split(',');
|
|
||||||
|
|
||||||
builder.Services.AddCors(options =>
|
|
||||||
{
|
|
||||||
options.AddPolicy("Policy", policy =>
|
|
||||||
{
|
|
||||||
if (allowedOrigins != null)
|
|
||||||
{
|
|
||||||
policy.WithOrigins(allowedOrigins)
|
|
||||||
.WithMethods(allowedMethods)
|
|
||||||
.WithHeaders(allowedHeaders);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
@ -154,16 +168,18 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
// Use CORS in the pipeline
|
// Use CORS in the pipeline
|
||||||
//app.UseCors("DevCorsPolicy");
|
app.UseCors("DevCorsPolicy");
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
//if (app.Environment.IsProduction())
|
||||||
|
//{
|
||||||
|
// app.UseCors("ProdCorsPolicy");
|
||||||
|
//}
|
||||||
|
|
||||||
|
//app.UseCors("AllowAll");
|
||||||
|
app.UseCors("DevCorsPolicy");
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (app.Environment.IsProduction())
|
|
||||||
//{
|
|
||||||
// app.UseCors("ProdCorsPolicy");
|
|
||||||
//}
|
|
||||||
|
|
||||||
app.UseCors("Policy");
|
|
||||||
|
|
||||||
app.UseStaticFiles(); // Enables serving static files
|
app.UseStaticFiles(); // Enables serving static files
|
||||||
|
|
||||||
//app.UseSerilogRequestLogging(); // This is Default Serilog Logging Middleware we are not using this because we're using custom logging middleware
|
//app.UseSerilogRequestLogging(); // This is Default Serilog Logging Middleware we are not using this because we're using custom logging middleware
|
||||||
|
Loading…
x
Reference in New Issue
Block a user