fix: 服务端使用本地IP
This commit is contained in:
parent
e7c8d3fb9e
commit
5da9d9f4e2
|
@ -59,7 +59,7 @@ try
|
|||
IssuerSigningKey = new SymmetricSecurityKey(
|
||||
Encoding.UTF8.GetBytes("my secret key 1234567890my secret key 1234567890")),
|
||||
};
|
||||
options.Authority = "http://localhost:5000";
|
||||
options.Authority = $"http://{Global.localhost}:5000";
|
||||
options.RequireHttpsMetadata = false;
|
||||
});
|
||||
// Add JWT Token Authorization Policy
|
||||
|
@ -175,7 +175,14 @@ try
|
|||
app.UseAuthorization();
|
||||
|
||||
// Swagger
|
||||
app.UseOpenApi();
|
||||
app.UseOpenApi(settings =>
|
||||
{
|
||||
settings.PostProcess = (document, httpRequest) =>
|
||||
{
|
||||
document.Servers.Clear();
|
||||
document.Servers.Add(new NSwag.OpenApiServer { Url = $"http://{Global.localhost}:5000" });
|
||||
};
|
||||
});
|
||||
app.UseSwaggerUi();
|
||||
|
||||
// Router
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"applicationUrl": "http://0.0.0.0:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
|
||||
|
@ -15,7 +15,7 @@
|
|||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7278;http://localhost:5000",
|
||||
"applicationUrl": "https://0.0.0.0:7278;http://0.0.0.0:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
public static class Global {
|
||||
|
||||
public static readonly string localhost = "172.31.2.228";
|
||||
|
||||
public static string GetLocalIPAddress()
|
||||
{
|
||||
var host = Dns.GetHostEntry(Dns.GetHostName());
|
||||
foreach (var ip in host.AddressList)
|
||||
{
|
||||
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
return ip.ToString();
|
||||
}
|
||||
}
|
||||
throw new Exception("No network adapters with an IPv4 address in the system!");
|
||||
}
|
||||
}
|
|
@ -148,10 +148,10 @@ public class VideoStreamController : ControllerBase
|
|||
FrameWidth = _videoStreamService.FrameWidth,
|
||||
FrameHeight = _videoStreamService.FrameHeight,
|
||||
Format = "MJPEG",
|
||||
HtmlUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-feed.html",
|
||||
MjpegUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-stream",
|
||||
SnapshotUrl = $"http://localhost:{_videoStreamService.ServerPort}/snapshot",
|
||||
UsbCameraUrl = $"http://localhost:{_videoStreamService.ServerPort}/usb-camera"
|
||||
HtmlUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/video-feed.html",
|
||||
MjpegUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/video-stream",
|
||||
SnapshotUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/snapshot",
|
||||
UsbCameraUrl = $"http://{Global.localhost}:{_videoStreamService.ServerPort}/usb-camera"
|
||||
};
|
||||
return TypedResults.Ok(result);
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public class VideoStreamController : ControllerBase
|
|||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(2); // 设置较短的超时时间
|
||||
var response = await httpClient.GetAsync($"http://localhost:{_videoStreamService.ServerPort}/");
|
||||
var response = await httpClient.GetAsync($"http://{Global.localhost}:{_videoStreamService.ServerPort}/");
|
||||
|
||||
// 只要能连接上就认为成功,不管返回状态
|
||||
isConnected = response.IsSuccessStatusCode;
|
||||
|
|
|
@ -311,7 +311,7 @@ public class HttpVideoStreamService : BackgroundService
|
|||
|
||||
// 创建 HTTP 监听器
|
||||
_httpListener = new HttpListener();
|
||||
_httpListener.Prefixes.Add($"http://localhost:{_serverPort}/");
|
||||
_httpListener.Prefixes.Add($"http://{Global.localhost}:{_serverPort}/");
|
||||
_httpListener.Start();
|
||||
|
||||
logger.Info("HTTP 视频流服务已启动,监听端口: {Port}", _serverPort);
|
||||
|
|
|
@ -15,7 +15,7 @@ export class VideoStreamClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -638,7 +638,7 @@ export class BsdlParserClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -691,7 +691,7 @@ export class DataClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1404,7 +1404,7 @@ export class DDSClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1644,7 +1644,7 @@ export class JtagClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2164,7 +2164,7 @@ export class LogicAnalyzerClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2609,7 +2609,7 @@ export class MatrixKeyClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2793,7 +2793,7 @@ export class NetConfigClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3419,7 +3419,7 @@ export class OscilloscopeApiClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3853,7 +3853,7 @@ export class PowerClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3925,7 +3925,7 @@ export class RemoteUpdateClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4266,7 +4266,7 @@ export class TutorialClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4315,7 +4315,7 @@ export class UDPClient {
|
|||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : window as any;
|
||||
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||
this.baseUrl = baseUrl ?? "http://172.31.2.228:5000";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue