Skip to content

Commit 642e01b

Browse files
authoredOct 17, 2024
fix(frontend): Update build directory and referenced paths (#4461)
1 parent 6cb174b commit 642e01b

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed
 

‎containers/app/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ RUN python openhands/core/download.py # No-op to download assets
9090
# openhands:openhands -> openhands:app
9191
RUN find /app \! -group app -exec chgrp app {} +
9292

93-
COPY --chown=openhands:app --chmod=770 --from=frontend-builder /app/build/client ./frontend/build
93+
COPY --chown=openhands:app --chmod=770 --from=frontend-builder /app/build ./frontend/build
9494
COPY --chown=openhands:app --chmod=770 ./containers/app/entrypoint.sh /app/entrypoint.sh
9595

9696
USER root

‎frontend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"dev": "npm run make-i18n && VITE_MOCK_API=false remix vite:dev",
4747
"dev:mock": "npm run make-i18n && VITE_MOCK_API=true remix vite:dev",
4848
"build": "npm run make-i18n && tsc && remix vite:build",
49-
"start": "npx sirv-cli build/client/ --single",
49+
"start": "npx sirv-cli build/ --single",
5050
"test": "vitest run",
5151
"test:coverage": "npm run make-i18n && vitest run --coverage",
5252
"dev_wsl": "VITE_WATCH_USE_POLLING=true vite",

‎frontend/vite.config.ts

+35-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import { vitePlugin as remix } from "@remix-run/dev";
88

99
export default defineConfig(({ mode }) => {
1010
const {
11-
VITE_BACKEND_HOST = "127.0.0.1:3000",
12-
VITE_USE_TLS = "false",
13-
VITE_FRONTEND_PORT = "3001",
14-
VITE_INSECURE_SKIP_VERIFY = "false",
15-
VITE_WATCH_USE_POLLING = "false",
11+
VITE_BACKEND_HOST = "127.0.0.1:3000",
12+
VITE_USE_TLS = "false",
13+
VITE_FRONTEND_PORT = "3001",
14+
VITE_INSECURE_SKIP_VERIFY = "false",
1615
} = loadEnv(mode, process.cwd());
1716

1817
const USE_TLS = VITE_USE_TLS === "true";
@@ -23,6 +22,35 @@ export default defineConfig(({ mode }) => {
2322
const API_URL = `${PROTOCOL}://${VITE_BACKEND_HOST}/`;
2423
const WS_URL = `${WS_PROTOCOL}://${VITE_BACKEND_HOST}/`;
2524
const FE_PORT = Number.parseInt(VITE_FRONTEND_PORT, 10);
25+
26+
/**
27+
* This script is used to unpack the client directory from the frontend build directory.
28+
* Remix SPA mode builds the client directory into the build directory. This function
29+
* moves the contents of the client directory to the build directory and then removes the
30+
* client directory.
31+
*
32+
* This script is used in the buildEnd function of the Vite config.
33+
*/
34+
const unpackClientDirectory = async () => {
35+
const fs = await import("fs");
36+
const path = await import("path");
37+
38+
const buildDir = path.resolve(__dirname, "build");
39+
const clientDir = path.resolve(buildDir, "client");
40+
41+
const files = await fs.promises.readdir(clientDir);
42+
await Promise.all(
43+
files.map((file) =>
44+
fs.promises.rename(
45+
path.resolve(clientDir, file),
46+
path.resolve(buildDir, file),
47+
),
48+
),
49+
);
50+
51+
await fs.promises.rmdir(clientDir);
52+
};
53+
2654
return {
2755
plugins: [
2856
!process.env.VITEST &&
@@ -33,6 +61,7 @@ export default defineConfig(({ mode }) => {
3361
v3_throwAbortReason: true,
3462
},
3563
appDirectory: "src",
64+
buildEnd: unpackClientDirectory,
3665
ssr: false,
3766
}),
3867
viteTsconfigPaths(),
@@ -67,5 +96,5 @@ export default defineConfig(({ mode }) => {
6796
include: ["src/**/*.{ts,tsx}"],
6897
},
6998
},
70-
}
99+
};
71100
});

‎openhands/server/listen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,4 @@ def github_callback(auth_code: AuthCode):
798798
)
799799

800800

801-
app.mount('/', StaticFiles(directory='./frontend/build/client', html=True), name='dist')
801+
app.mount('/', StaticFiles(directory='./frontend/build', html=True), name='dist')

0 commit comments

Comments
 (0)