Skip to content

Commit e9f16ca

Browse files
committed
build: custom base path not work
1 parent 9504616 commit e9f16ca

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ public String index(){
2929
@GetMapping({"/api/search", "/api/search.data"})
3030
@ResponseBody
3131
public String handleSearch(HttpServletRequest request, HttpServletResponse response) {
32-
String fullPath = request.getRequestURI();
32+
String fullPath = request.getRequestURI().replace(request.getContextPath(), "");
3333
String relativePath = fullPath.substring(1);
3434
return renderFileData(relativePath, response);
3535
}
3636

3737
@GetMapping({"/ui/docs/*.data", "/ui/*.data"})
3838
@ResponseBody
3939
public String handleDataFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
40-
String fullPath = request.getRequestURI();
40+
String fullPath = request.getRequestURI().replace(request.getContextPath(), "");
4141
String relativePath = fullPath.substring(4);
4242
return renderFileData(relativePath, response);
4343
}
4444

4545

4646
@GetMapping("/ui/**")
4747
public String handleHtmlView(HttpServletRequest request) {
48-
String fullPath = request.getRequestURI();
48+
String fullPath = request.getRequestURI().replace(request.getContextPath(), "");
4949
if ("/ui".equals(fullPath) || "/ui/".equals(fullPath)) {
5050
return "index";
5151
}

web/copy-build.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
1+
import { existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
22
import { cp } from "node:fs/promises";
33
import { join, resolve } from "node:path";
44

@@ -9,6 +9,31 @@ const TEMPLATES_DIR = join(BASE_DIR, "templates");
99
const BUILD_DIR = resolve("build/client");
1010
const BUILD_ASSERTS_DIR = join(BUILD_DIR, "assets");
1111

12+
function findUiDirectory(baseDir, maxDepth = 5) {
13+
function search(currentDir, depth) {
14+
if (depth > maxDepth) return null;
15+
16+
const entries = readdirSync(currentDir);
17+
18+
for (const entry of entries) {
19+
const fullPath = join(currentDir, entry);
20+
21+
if (!statSync(fullPath).isDirectory()) continue;
22+
23+
if (entry === "ui") {
24+
return fullPath;
25+
}
26+
27+
const found = search(fullPath, depth + 1);
28+
if (found) return found;
29+
}
30+
31+
return null;
32+
}
33+
34+
return search(baseDir, 0);
35+
}
36+
1237
async function main() {
1338
if (!existsSync(BUILD_DIR)) {
1439
console.error(`Error: ${BUILD_DIR} does not exist`);
@@ -32,7 +57,13 @@ async function main() {
3257
console.error("Error copying assets:", err);
3358
process.exit(1);
3459
}
35-
await cp(join(BUILD_DIR, "ui"), TEMPLATES_DIR, { recursive: true });
60+
61+
const uiDir = findUiDirectory(BUILD_DIR);
62+
if (!uiDir) {
63+
console.error(`Error: ui directory not found in ${BUILD_DIR}`);
64+
process.exit(1);
65+
}
66+
await cp(uiDir, join(TEMPLATES_DIR), { recursive: true });
3667
console.log("SpringBoot resources updated successfully");
3768
}
3869

web/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { env } from "node:process";
12
import { reactRouter } from "@react-router/dev/vite";
23
import tailwindcss from "@tailwindcss/vite";
34
import mdx from "fumadocs-mdx/vite";
@@ -7,6 +8,7 @@ import tsconfigPaths from "vite-tsconfig-paths";
78
import * as MdxConfig from "./source.config";
89

910
export default defineConfig({
11+
base: `${env.VITE_APP_API_URL}/`,
1012
plugins: [
1113
mdx(MdxConfig),
1214
tailwindcss(),

0 commit comments

Comments
 (0)