Besjon Cifliku commited on
Commit
8042dc1
·
1 Parent(s): 1710209

fix: fronentd doees not load in hf space

Browse files
Dockerfile CHANGED
@@ -10,7 +10,7 @@ WORKDIR /app/frontend
10
  COPY frontend/package.json frontend/package-lock.json ./
11
  RUN npm ci
12
  COPY frontend/ ./
13
- RUN npm run build
14
 
15
  # Stage 2: Python runtime
16
  FROM python:3.12-slim AS runtime
 
10
  COPY frontend/package.json frontend/package-lock.json ./
11
  RUN npm ci
12
  COPY frontend/ ./
13
+ RUN npm run build && node inline-assets.cjs
14
 
15
  # Stage 2: Python runtime
16
  FROM python:3.12-slim AS runtime
frontend/inline-assets.cjs ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Post-build: inline CSS and JS into index.html so the entire frontend
3
+ * is served as a single response. HuggingFace Spaces' proxy only
4
+ * forwards the initial page request to the container — sub-resource
5
+ * requests (JS, CSS) never arrive, so they must be embedded.
6
+ */
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+
10
+ const distDir = path.join(__dirname, "dist");
11
+ const htmlPath = path.join(distDir, "index.html");
12
+
13
+ if (!fs.existsSync(htmlPath)) {
14
+ console.log("No dist/index.html — skipping inline");
15
+ process.exit(0);
16
+ }
17
+
18
+ let html = fs.readFileSync(htmlPath, "utf8");
19
+
20
+ // Inline CSS <link> tags
21
+ html = html.replace(
22
+ /<link[^>]+href="([^"]+\.css)"[^>]*\/?>/g,
23
+ (match, href) => {
24
+ const file = path.join(distDir, href.replace(/^\.\//, ""));
25
+ if (!fs.existsSync(file)) return match;
26
+ console.log(" CSS:", href);
27
+ return "<style>" + fs.readFileSync(file, "utf8") + "</style>";
28
+ }
29
+ );
30
+
31
+ // Inline JS <script> tags (escape </script> in content)
32
+ html = html.replace(
33
+ /<script([^>]*)src="([^"]+\.js)"([^>]*)><\/script>/g,
34
+ (match, _pre, src, _post) => {
35
+ const file = path.join(distDir, src.replace(/^\.\//, ""));
36
+ if (!fs.existsSync(file)) return match;
37
+ console.log(" JS: ", src);
38
+ const code = fs.readFileSync(file, "utf8").replace(/<\/script/gi, "<\\/script");
39
+ return '<script type="module">' + code + "</script>";
40
+ }
41
+ );
42
+
43
+ fs.writeFileSync(htmlPath, html);
44
+ console.log("Inlined assets into index.html:", Math.round(html.length / 1024), "KB");
frontend/vite.config.ts CHANGED
@@ -4,6 +4,15 @@ import react from "@vitejs/plugin-react";
4
  export default defineConfig({
5
  plugins: [react()],
6
  base: "./",
 
 
 
 
 
 
 
 
 
7
  server: {
8
  proxy: {
9
  "/api/logs/stream": {
 
4
  export default defineConfig({
5
  plugins: [react()],
6
  base: "./",
7
+ build: {
8
+ assetsDir: "static",
9
+ cssCodeSplit: false,
10
+ rollupOptions: {
11
+ output: {
12
+ inlineDynamicImports: true,
13
+ },
14
+ },
15
+ },
16
  server: {
17
  proxy: {
18
  "/api/logs/stream": {