mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 20:40:55 +00:00
Сделал автоматическую ссылку на QR, а так же в appsettings есть возможность выбора порта
This commit is contained in:
1 parent
2482e30cb3
commit
4b78e211f6
9 files changed
+69
-24
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace CartriX.Api.Classes
|
||||
{
|
||||
@@ -38,5 +39,24 @@ namespace CartriX.Api.Classes
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetLocalIp()
|
||||
{
|
||||
foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (ni.OperationalStatus != OperationalStatus.Up) continue;
|
||||
if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback) continue;
|
||||
|
||||
var props = ni.GetIPProperties();
|
||||
foreach (var ua in props.UnicastAddresses)
|
||||
{
|
||||
if (ua.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
return ua.Address.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "127.0.0.1";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace CartriX.Api.Controllers.Network
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class NetworkController : ControllerBase
|
||||
public class NetworkController(IConfiguration configuration) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Доступность
|
||||
@@ -39,5 +39,20 @@ namespace CartriX.Api.Controllers.Network
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status404NotFound)]
|
||||
[HttpGet(nameof(Ping))]
|
||||
public async Task<ActionResult> Ping([FromQuery] string IpAddressOrHostname) => (await NetworkHelper.PingHostAsync(IpAddressOrHostname)) ? StatusCode(200, true) : StatusCode(404, false);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить адрес
|
||||
/// </summary>
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[HttpGet(nameof(BaseAddress))]
|
||||
public async Task<ActionResult> BaseAddress()
|
||||
{
|
||||
var port = configuration.GetValue<int>("Server:Port");
|
||||
var ip = NetworkHelper.GetLocalIp();
|
||||
return Ok(new Uri($"http://{ip}:{port}"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,9 @@ builder.Services.AddCors(options =>
|
||||
});
|
||||
});
|
||||
|
||||
builder.WebHost.UseUrls(
|
||||
"http://0.0.0.0:5000"
|
||||
);
|
||||
|
||||
builder.WebHost.UseUrls("http://0.0.0.0:5067");
|
||||
|
||||
|
||||
builder.Services.AddOpenApi(options =>
|
||||
{
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"SQL": "Data Source = E:\\User\\Documents\\db.db"
|
||||
"SQL": "Data Source = C:\\Users\\hk\\Documents\\db.db"
|
||||
},
|
||||
"PrinterScanner": {
|
||||
"IntervalMinutes": 1
|
||||
},
|
||||
"Server": {
|
||||
"Port" : "5067"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user