diff --git a/CartriX.Api/Program.cs b/CartriX.Api/Program.cs index 169ecbd..6a90a68 100644 --- a/CartriX.Api/Program.cs +++ b/CartriX.Api/Program.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Scalar.AspNetCore; var builder = WebApplication.CreateBuilder(args); + builder.Services.AddControllers(); builder.Services.AddScoped(); @@ -16,42 +17,61 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); - builder.Services.AddHostedService(); +// CORS builder.Services.AddCors(options => { options.AddPolicy("AllowAll", policy => { - policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); + policy + .AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod(); }); }); + +// Слушаем все сетевые интерфейсы +builder.WebHost.UseUrls( + "http://192.168.0.26:5917" +); + builder.Services.AddOpenApi(); + builder.Services.AddDbContext(options => { - options.UseSqlite(builder.Configuration.GetConnectionString("DevSQL")); + options.UseSqlite( + builder.Configuration.GetConnectionString("DevSQL")); }); var app = builder.Build(); -app.MapControllers(); + +// ПОРЯДОК ВАЖЕН! app.UseRouting(); + +// CORS должен быть ДО MapControllers() app.UseCors("AllowAll"); + if (app.Environment.IsDevelopment()) { app.MapOpenApi(); + app.MapScalarApiReference(options => { options.HideSearch = true; options.HideModels = true; options.Layout = ScalarLayout.Modern; options.DefaultOpenAllTags = false; - options.Agent = new ScalarAgentOptions() + options.Agent = new ScalarAgentOptions { - Disabled = true, + Disabled = true }; options.Title = "CartriX API Documentation"; options.Theme = ScalarTheme.DeepSpace; }); } -app.Run(); +// Контроллеры должны быть ПОСЛЕ UseCors() +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/CartriX.Api/Properties/launchSettings.json b/CartriX.Api/Properties/launchSettings.json index 58d8645..63e7def 100644 --- a/CartriX.Api/Properties/launchSettings.json +++ b/CartriX.Api/Properties/launchSettings.json @@ -3,7 +3,7 @@ "http": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "http://localhost:5197/scalar", + "launchUrl": "http://0.0.0.0:5197/scalar", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, @@ -13,7 +13,7 @@ "https": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "https://localhost:7209/scalar", + "launchUrl": "https://0.0.0.0:7209/scalar", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/CartriX.Shared/ApiRoutes.cs b/CartriX.Shared/ApiRoutes.cs index c364475..7d459a8 100644 --- a/CartriX.Shared/ApiRoutes.cs +++ b/CartriX.Shared/ApiRoutes.cs @@ -4,7 +4,7 @@ namespace CartriX.Shared { public class ApiRoutes { - static string baseUrl = "http://localhost:5197/api"; + static string baseUrl = "http://192.168.0.26:5917/api"; static public class Cartridge { public static string Add => $"{baseUrl}/{nameof(Cartridge)}/{nameof(Add)}"; @@ -14,6 +14,10 @@ namespace CartriX.Shared public static string ModelsAndManufacturers => $"{baseUrl}/{nameof(Cartridge)}/{nameof(ModelsAndManufacturers)}"; public static string Item(int id) => $"{baseUrl}/{nameof(Cartridge)}/{nameof(Item)}"; } + static public class Report + { + public static string GetReportToDatePerCountPrinted => $"{baseUrl}/{nameof(Report)}/{nameof(GetReportToDatePerCountPrinted)}"; + } static public class Article { public static string ListArticlesByName => $"{baseUrl}/{nameof(Article)}/{nameof(ListArticlesByName)}"; diff --git a/CartriX.Web/Pages/Dashboard.razor b/CartriX.Web/Pages/Dashboard.razor index b44e4d2..3906a08 100644 --- a/CartriX.Web/Pages/Dashboard.razor +++ b/CartriX.Web/Pages/Dashboard.razor @@ -31,7 +31,7 @@ protected override async Task OnInitializedAsync() { - var response = await httpClient.GetAsync("http://localhost:5197/api/Report/GetReportToDatePerCountPrinted"); + var response = await httpClient.GetAsync(ApiRoutes.Report.GetReportToDatePerCountPrinted); dataPerPrinteds = JsonConvert.DeserializeObject>(await response.Content.ReadAsStringAsync()); dataPerPrinteds = dataPerPrinteds?.OrderBy(x => x.date).ToList(); diff --git a/CartriX.Web/Program.cs b/CartriX.Web/Program.cs index 9a7f9e7..efe934e 100644 --- a/CartriX.Web/Program.cs +++ b/CartriX.Web/Program.cs @@ -4,10 +4,11 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Radzen; var builder = WebAssemblyHostBuilder.CreateDefault(args); + builder.Services.AddRadzenComponents(); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://192.168.0.26:5001/") }); await builder.Build().RunAsync(); diff --git a/CartriX.Web/Properties/launchSettings.json b/CartriX.Web/Properties/launchSettings.json index a629bf2..20d71c0 100644 --- a/CartriX.Web/Properties/launchSettings.json +++ b/CartriX.Web/Properties/launchSettings.json @@ -6,7 +6,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "https://localhost:51955;http://localhost:51956" + "applicationUrl": "https://0.0.0.0:5000;http://0.0.0.0:5001" } } } \ No newline at end of file