Skip to content

Commit

Permalink
fix(frontend): Update build directory and referenced paths (#4461)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape authored Oct 17, 2024
1 parent 6cb174b commit 642e01b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion containers/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ RUN python openhands/core/download.py # No-op to download assets
# openhands:openhands -> openhands:app
RUN find /app \! -group app -exec chgrp app {} +

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

USER root
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dev": "npm run make-i18n && VITE_MOCK_API=false remix vite:dev",
"dev:mock": "npm run make-i18n && VITE_MOCK_API=true remix vite:dev",
"build": "npm run make-i18n && tsc && remix vite:build",
"start": "npx sirv-cli build/client/ --single",
"start": "npx sirv-cli build/ --single",
"test": "vitest run",
"test:coverage": "npm run make-i18n && vitest run --coverage",
"dev_wsl": "VITE_WATCH_USE_POLLING=true vite",
Expand Down
41 changes: 35 additions & 6 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { vitePlugin as remix } from "@remix-run/dev";

export default defineConfig(({ mode }) => {
const {
VITE_BACKEND_HOST = "127.0.0.1:3000",
VITE_USE_TLS = "false",
VITE_FRONTEND_PORT = "3001",
VITE_INSECURE_SKIP_VERIFY = "false",
VITE_WATCH_USE_POLLING = "false",
VITE_BACKEND_HOST = "127.0.0.1:3000",
VITE_USE_TLS = "false",
VITE_FRONTEND_PORT = "3001",
VITE_INSECURE_SKIP_VERIFY = "false",
} = loadEnv(mode, process.cwd());

const USE_TLS = VITE_USE_TLS === "true";
Expand All @@ -23,6 +22,35 @@ export default defineConfig(({ mode }) => {
const API_URL = `${PROTOCOL}://${VITE_BACKEND_HOST}/`;
const WS_URL = `${WS_PROTOCOL}://${VITE_BACKEND_HOST}/`;
const FE_PORT = Number.parseInt(VITE_FRONTEND_PORT, 10);

/**
* This script is used to unpack the client directory from the frontend build directory.
* Remix SPA mode builds the client directory into the build directory. This function
* moves the contents of the client directory to the build directory and then removes the
* client directory.
*
* This script is used in the buildEnd function of the Vite config.
*/
const unpackClientDirectory = async () => {
const fs = await import("fs");
const path = await import("path");

const buildDir = path.resolve(__dirname, "build");
const clientDir = path.resolve(buildDir, "client");

const files = await fs.promises.readdir(clientDir);
await Promise.all(
files.map((file) =>
fs.promises.rename(
path.resolve(clientDir, file),
path.resolve(buildDir, file),
),
),
);

await fs.promises.rmdir(clientDir);
};

return {
plugins: [
!process.env.VITEST &&
Expand All @@ -33,6 +61,7 @@ export default defineConfig(({ mode }) => {
v3_throwAbortReason: true,
},
appDirectory: "src",
buildEnd: unpackClientDirectory,
ssr: false,
}),
viteTsconfigPaths(),
Expand Down Expand Up @@ -67,5 +96,5 @@ export default defineConfig(({ mode }) => {
include: ["src/**/*.{ts,tsx}"],
},
},
}
};
});
2 changes: 1 addition & 1 deletion openhands/server/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,4 @@ def github_callback(auth_code: AuthCode):
)


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

0 comments on commit 642e01b

Please sign in to comment.