version 2
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using FluentValidation;
|
||||
using GreenHome.AI.DeepSeek;
|
||||
using GreenHome.Application;
|
||||
using GreenHome.Infrastructure;
|
||||
using GreenHome.Sms.Ippanel;
|
||||
@@ -15,26 +16,35 @@ builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddAutoMapper(typeof(GreenHome.Application.MappingProfile));
|
||||
builder.Services.AddValidatorsFromAssemblyContaining<GreenHome.Application.DeviceDtoValidator>();
|
||||
|
||||
// CORS for Next.js dev (adjust origins as needed)
|
||||
// CORS Configuration
|
||||
const string CorsPolicy = "DefaultCors";
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(CorsPolicy, policy =>
|
||||
policy
|
||||
.WithOrigins(
|
||||
"http://green.nabaksoft.ir",
|
||||
"https://green.nabaksoft.ir",
|
||||
"http://gh1.nabaksoft.ir",
|
||||
"https://gh1.nabaksoft.ir",
|
||||
"http://localhost:3000",
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
"https://localhost:3000"
|
||||
)
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials()
|
||||
);
|
||||
{
|
||||
if (builder.Environment.IsDevelopment())
|
||||
{
|
||||
// در محیط Development همه origin ها مجاز هستند
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
}
|
||||
else
|
||||
{
|
||||
// در محیط Production فقط دامنههای مشخص
|
||||
policy
|
||||
.WithOrigins(
|
||||
"http://green.nabaksoft.ir",
|
||||
"https://green.nabaksoft.ir",
|
||||
"http://gh1.nabaksoft.ir",
|
||||
"https://gh1.nabaksoft.ir"
|
||||
)
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<GreenHome.Infrastructure.GreenHomeDbContext>(options =>
|
||||
@@ -46,6 +56,10 @@ builder.Services.AddScoped<GreenHome.Application.ITelemetryService, GreenHome.In
|
||||
builder.Services.AddScoped<GreenHome.Application.IDeviceSettingsService, GreenHome.Infrastructure.DeviceSettingsService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.IAuthService, GreenHome.Infrastructure.AuthService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.IAlertService, GreenHome.Infrastructure.AlertService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.IAlertConditionService, GreenHome.Infrastructure.AlertConditionService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.ISunCalculatorService, GreenHome.Infrastructure.SunCalculatorService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.IAIQueryService, GreenHome.Infrastructure.AIQueryService>();
|
||||
builder.Services.AddScoped<GreenHome.Application.IDailyReportService, GreenHome.Infrastructure.DailyReportService>();
|
||||
|
||||
// SMS Service Configuration
|
||||
builder.Services.AddIppanelSms(builder.Configuration);
|
||||
@@ -53,6 +67,9 @@ builder.Services.AddIppanelSms(builder.Configuration);
|
||||
// Voice Call Service Configuration
|
||||
builder.Services.AddAvanakVoiceCall(builder.Configuration);
|
||||
|
||||
// AI Service Configuration
|
||||
builder.Services.AddDeepSeek(builder.Configuration);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Apply pending migrations automatically
|
||||
@@ -78,7 +95,11 @@ using (var scope = app.Services.CreateScope())
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
// HTTPS Redirection فقط در Production
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
app.UseCors(CorsPolicy);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user