build: custom base path not work

This commit is contained in:
ReaJason
2025-12-08 01:43:41 +08:00
parent 95046169ed
commit e9f16ca32e
3 changed files with 38 additions and 5 deletions
@@ -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";
}
+33 -2
View File
@@ -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");
}
+2
View File
@@ -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(),