Skip to content

Commit 3c80a41

Browse files
authored
fix: load 3d models when in web build (#3562)
1 parent ff4b62d commit 3c80a41

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

vite.config.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import vue from "@vitejs/plugin-vue2";
44
import path from "node:path";
55
import { readFileSync } from "node:fs";
66

7+
function serveFileFromDirectory(directory) {
8+
return (req, res, next) => {
9+
const filePath = req.url.replace(new RegExp(`^/${directory}/`), "");
10+
const absolutePath = path.resolve(process.cwd(), directory, filePath);
11+
12+
try {
13+
const fileContents = readFileSync(absolutePath, "utf-8");
14+
res.end(fileContents);
15+
} catch (e) {
16+
// If file not found or any other error, pass to the next middleware
17+
next();
18+
}
19+
};
20+
}
21+
722
/**
823
* This is plugin to work around the file structure required nwjs.
924
* In future this can be dropped if we restructure folder structure
@@ -17,24 +32,9 @@ function serveLocalesPlugin() {
1732
return () => {
1833
server.middlewares.use((req, res, next) => {
1934
if (req.url.startsWith("/locales/")) {
20-
// Extract the file path from the URL
21-
const filePath = req.url.replace(/^\/locales\//, "");
22-
const absolutePath = path.resolve(
23-
process.cwd(),
24-
"locales",
25-
filePath,
26-
);
27-
28-
try {
29-
const fileContents = readFileSync(
30-
absolutePath,
31-
"utf-8",
32-
);
33-
res.end(fileContents);
34-
} catch (e) {
35-
// If file not found or any other error, pass to the next middleware
36-
next();
37-
}
35+
serveFileFromDirectory('locales')(req, res, next);
36+
} else if (req.url.startsWith("/resources/")) {
37+
serveFileFromDirectory('resources')(req, res, next);
3838
} else {
3939
next();
4040
}

0 commit comments

Comments
 (0)