Refactor FaceEmbeddingService to use configuration for API base URL and update CORS policy to read origins from configuration
This commit is contained in:
@@ -9,6 +9,7 @@ using _0_Framework.Application;
|
||||
using _0_Framework.Application.FaceEmbedding;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _0_Framework.Infrastructure;
|
||||
@@ -24,12 +25,12 @@ public class FaceEmbeddingService : IFaceEmbeddingService
|
||||
private readonly string _apiBaseUrl;
|
||||
|
||||
public FaceEmbeddingService(IHttpClientFactory httpClientFactory, ILogger<FaceEmbeddingService> logger,
|
||||
IFaceEmbeddingNotificationService notificationService = null)
|
||||
IConfiguration configuration, IFaceEmbeddingNotificationService notificationService = null)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_logger = logger;
|
||||
_notificationService = notificationService;
|
||||
_apiBaseUrl = "http://localhost:8000";
|
||||
_apiBaseUrl = configuration["FaceEmbeddingApi:BaseUrl"] ?? "http://localhost:8000";
|
||||
}
|
||||
|
||||
public async Task<OperationResult> GenerateEmbeddingsAsync(long employeeId, long workshopId,
|
||||
|
||||
@@ -230,15 +230,10 @@ try
|
||||
#region CORS
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
var corsOrigins = builder.Configuration.GetSection("CorsOrigins").Get<string[]>() ?? Array.Empty<string>();
|
||||
options.AddPolicy("AllowSpecificOrigins", policy =>
|
||||
{
|
||||
policy.WithOrigins(
|
||||
"http://localhost:3000", "http://localhost:4000", "http://localhost:4001",
|
||||
"http://localhost:4002", "http://localhost:3001", "https://gozareshgir.ir",
|
||||
"https://dad-mehr.ir", "https://admin.dad-mehr.ir", "https://client.dad-mehr.ir",
|
||||
"https://admin.gozareshgir.ir", "https://client.gozareshgir.ir",
|
||||
"https://admin.dadmehrg.ir", "https://client.dadmehrg.ir", "http://localhost:3300"
|
||||
)
|
||||
policy.WithOrigins(corsOrigins)
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
|
||||
Reference in New Issue
Block a user