diff --git a/boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java b/boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java index 6d8c2942..0561ba2f 100644 --- a/boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java +++ b/boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java @@ -29,7 +29,7 @@ public class ViewController { @GetMapping({"/api/search", "/api/search.data"}) @ResponseBody public String handleSearch(HttpServletRequest request, HttpServletResponse response) { - String fullPath = request.getRequestURI(); + String fullPath = request.getRequestURI().replace(request.getContextPath(), ""); String relativePath = fullPath.substring(1); return renderFileData(relativePath, response); } @@ -37,7 +37,7 @@ public class ViewController { @GetMapping({"/ui/docs/*.data", "/ui/*.data"}) @ResponseBody public String handleDataFile(HttpServletRequest request, HttpServletResponse response) throws IOException { - String fullPath = request.getRequestURI(); + String fullPath = request.getRequestURI().replace(request.getContextPath(), ""); String relativePath = fullPath.substring(4); return renderFileData(relativePath, response); } @@ -45,7 +45,7 @@ public class ViewController { @GetMapping("/ui/**") public String handleHtmlView(HttpServletRequest request) { - String fullPath = request.getRequestURI(); + String fullPath = request.getRequestURI().replace(request.getContextPath(), ""); if ("/ui".equals(fullPath) || "/ui/".equals(fullPath)) { return "index"; } diff --git a/web/copy-build.js b/web/copy-build.js index 1b840859..b020ec7d 100644 --- a/web/copy-build.js +++ b/web/copy-build.js @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs"; +import { existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs"; import { cp } from "node:fs/promises"; import { join, resolve } from "node:path"; @@ -9,6 +9,31 @@ const TEMPLATES_DIR = join(BASE_DIR, "templates"); const BUILD_DIR = resolve("build/client"); const BUILD_ASSERTS_DIR = join(BUILD_DIR, "assets"); +function findUiDirectory(baseDir, maxDepth = 5) { + function search(currentDir, depth) { + if (depth > maxDepth) return null; + + const entries = readdirSync(currentDir); + + for (const entry of entries) { + const fullPath = join(currentDir, entry); + + if (!statSync(fullPath).isDirectory()) continue; + + if (entry === "ui") { + return fullPath; + } + + const found = search(fullPath, depth + 1); + if (found) return found; + } + + return null; + } + + return search(baseDir, 0); +} + async function main() { if (!existsSync(BUILD_DIR)) { console.error(`Error: ${BUILD_DIR} does not exist`); @@ -32,7 +57,13 @@ async function main() { console.error("Error copying assets:", err); process.exit(1); } - await cp(join(BUILD_DIR, "ui"), TEMPLATES_DIR, { recursive: true }); + + const uiDir = findUiDirectory(BUILD_DIR); + if (!uiDir) { + console.error(`Error: ui directory not found in ${BUILD_DIR}`); + process.exit(1); + } + await cp(uiDir, join(TEMPLATES_DIR), { recursive: true }); console.log("SpringBoot resources updated successfully"); } diff --git a/web/vite.config.ts b/web/vite.config.ts index 9f066318..2e5a1878 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,3 +1,4 @@ +import { env } from "node:process"; import { reactRouter } from "@react-router/dev/vite"; import tailwindcss from "@tailwindcss/vite"; import mdx from "fumadocs-mdx/vite"; @@ -7,6 +8,7 @@ import tsconfigPaths from "vite-tsconfig-paths"; import * as MdxConfig from "./source.config"; export default defineConfig({ + base: `${env.VITE_APP_API_URL}/`, plugins: [ mdx(MdxConfig), tailwindcss(),