From d55d8edd2ffc8e490802f15d1e7f9f685f7068dc Mon Sep 17 00:00:00 2001 From: yukaidi Date: Sun, 31 May 2026 14:00:45 +0800 Subject: [PATCH] =?UTF-8?q?AppMain:=20=E5=90=AF=E5=8A=A8=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=8D=E7=AB=AF=E9=A1=B5=E9=9D=A2=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E5=9C=B0=E5=9D=80=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/qaiu/lz/AppMain.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/web-service/src/main/java/cn/qaiu/lz/AppMain.java b/web-service/src/main/java/cn/qaiu/lz/AppMain.java index 7e0d30a..3460dbc 100644 --- a/web-service/src/main/java/cn/qaiu/lz/AppMain.java +++ b/web-service/src/main/java/cn/qaiu/lz/AppMain.java @@ -21,6 +21,8 @@ import io.vertx.core.shareddata.LocalMap; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateFormatUtils; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Date; import static cn.qaiu.vx.core.util.ConfigConstant.LOCAL; @@ -78,12 +80,33 @@ public class AppMain { System.out.println("数据库连接成功"); // 加载演练场解析器 - loadPlaygroundParsers(); - String addr = jsonObject.getJsonObject(ConfigConstant.SERVER).getString("domainName"); if (addr == null || addr.isBlank()) { addr = "http://127.0.0.1:" + jsonObject.getJsonObject(ConfigConstant.SERVER).getInteger("port", 6400); } + // 读取代理配置获取前端页面端口(同步读文件,避免阻塞 event loop) + String proxyConfName = jsonObject.getString("proxyConf", "server-proxy"); + String pageAddr = addr; + try { + String configFile = proxyConfName + ".yml"; + Path configPath = Path.of("resources", configFile); + if (!Files.exists(configPath)) { + configPath = Path.of(configFile); + } + if (Files.exists(configPath)) { + String yamlContent = Files.readString(configPath); + java.util.regex.Matcher m = java.util.regex.Pattern + .compile("^\\s*-\\s+listen:\\s*(\\d+)", java.util.regex.Pattern.MULTILINE) + .matcher(yamlContent); + if (m.find()) { + int pagePort = Integer.parseInt(m.group(1)); + pageAddr = "http://127.0.0.1:" + pagePort; + } + } + } catch (Exception e) { + log.warn("读取代理配置失败,使用默认页面地址: {}", e.getMessage()); + } + loadPlaygroundParsers(pageAddr); System.out.println("启动成功: \n本地服务地址: " + addr); }); }); @@ -125,7 +148,7 @@ public class AppMain { /** * 在启动时加载所有已发布的演练场解析器 */ - private static void loadPlaygroundParsers() { + private static void loadPlaygroundParsers(String accessAddr) { DbService dbService = AsyncServiceUtil.getAsyncServiceInstance(DbService.class); dbService.getPlaygroundParserList().onSuccess(result -> { @@ -163,6 +186,7 @@ public class AppMain { } else { log.info("未找到已发布的演练场解析器"); } + log.info("服务已启动,可通过 {} 访问页面", accessAddr); }).onFailure(e -> { log.error("加载演练场解析器列表失败", e); });