ну конечно, кто будет коннект метод то вызывать? :/ а потом спрашиваю, почему же у меня ничего не работает? все, починила

This commit is contained in:
ekallin 2024-04-07 00:13:50 +03:00
parent ceb0ca6390
commit b393856069
4 changed files with 28 additions and 27 deletions

View File

@ -9,9 +9,10 @@ namespace SushiBarClientApp
{ {
private static readonly HttpClient _client = new(); private static readonly HttpClient _client = new();
public static ClientViewModel? Client { get; set; } = null; public static ClientViewModel? Client { get; set; } = null;
public static void Connect(IConfiguration configuration) public static void Connect(IConfiguration configuration)
{ {
_client.BaseAddress = new Uri("http://localhost:5262/"); _client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
} }

View File

@ -1,10 +1,9 @@
using SushiBarClientApp;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {
@ -12,16 +11,11 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllerRoute( app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run(); app.Run();

View File

@ -6,6 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>

View File

@ -1,16 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<log4net> <configuration>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="logs/SushiBarRestApi.log" /> <log4net>
<appendToFile value="true" /> <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<maximumFileSize value="100KB" /> <file value="logs/SushiBarRestApi.log" />
<maxSizeRollBackups value="2" /> <appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout"> <maximumFileSize value="100KB" />
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" /> <maxSizeRollBackups value="2" />
</layout> <layout type="log4net.Layout.PatternLayout">
</appender> <conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
<root> </layout>
<level value="TRACE" /> </appender>
<appender-ref ref="RollingFile" /> <root>
</root> <level value="TRACE" />
</log4net> <appender-ref ref="RollingFile" />
</root>
</log4net>
</configuration>