|
@@ -1,24 +1,43 @@
|
|
|
package com.guanlan.gateway.web;
|
|
package com.guanlan.gateway.web;
|
|
|
|
|
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
|
|
|
|
+import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
-import java.net.URI;
|
|
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 门户入口重定向(P12):`/` → `/web/`。
|
|
|
|
|
|
|
+ * 门户代理(P12 入口切换):根路径 `/` 与 `/index.html` 从**旧网关**(退到 28086)取回门户 HTML 原样返回。
|
|
|
*
|
|
*
|
|
|
- * <p>用户令「先把入口切到 Java 网关」:原来的门户页由 Python 网关提供,切换后统一由 Java 网关承接,
|
|
|
|
|
- * 根路径直接送到 Vue 工作台(`/web/`,由 web 路由 StripPrefix 后打到 28110)。
|
|
|
|
|
|
|
+ * <p>为什么不用路由谓词:`Path=/` 在 Spring Cloud Gateway 里不匹配根请求(实逮 `/` 仍 404),
|
|
|
|
|
+ * 故用控制器显式代理 —— 这样"入口是 Java 网关"与"根路径仍是门户页"(门禁 `scripts/pages_audit.py` 的判据)
|
|
|
|
|
+ * 同时成立;Vue 工作台仍走 `/web/`。
|
|
|
*/
|
|
*/
|
|
|
@RestController
|
|
@RestController
|
|
|
public class PortalController {
|
|
public class PortalController {
|
|
|
|
|
|
|
|
- @GetMapping("/")
|
|
|
|
|
- public Mono<ResponseEntity<Void>> portal() {
|
|
|
|
|
- return Mono.just(ResponseEntity.status(HttpStatus.FOUND).location(URI.create("/web/")).build());
|
|
|
|
|
|
|
+ private final WebClient web;
|
|
|
|
|
+
|
|
|
|
|
+ public PortalController(@Value("${guanlan.portal-upstream:http://127.0.0.1:28086}") String upstream) {
|
|
|
|
|
+ // ★实逮:门户页 20 MB(内联经典图表脚本)远超 WebClient 默认 256 KB 内存缓冲 ⇒ 必须放开
|
|
|
|
|
+ this.web = WebClient.builder().baseUrl(upstream)
|
|
|
|
|
+ .exchangeStrategies(ExchangeStrategies.builder()
|
|
|
|
|
+ .codecs(c -> c.defaultCodecs().maxInMemorySize(-1)).build())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping(value = {"/", "/index.html"}, produces = "text/html; charset=utf-8")
|
|
|
|
|
+ public Mono<ResponseEntity<String>> portal() {
|
|
|
|
|
+ return web.get().uri("/").retrieve().bodyToMono(String.class)
|
|
|
|
|
+ .timeout(Duration.ofSeconds(60))
|
|
|
|
|
+ .map(html -> ResponseEntity.ok().contentType(MediaType.valueOf("text/html; charset=utf-8")).body(html))
|
|
|
|
|
+ .onErrorResume(e -> Mono.just(ResponseEntity.status(503)
|
|
|
|
|
+ .contentType(MediaType.valueOf("text/html; charset=utf-8"))
|
|
|
|
|
+ .body("<h1>门户暂不可用</h1><p>旧网关(28086)未启动: " + e.getClass().getSimpleName() + "</p>")));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|