@gxp-dev/tools 2.0.61 → 2.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/vite.config.js +36 -36
package/package.json
CHANGED
package/template/vite.config.js
CHANGED
|
@@ -208,44 +208,44 @@ export default defineConfig(({ mode }) => {
|
|
|
208
208
|
name: "spa-fallback",
|
|
209
209
|
configureServer(server) {
|
|
210
210
|
return () => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
server.middlewares.use((req, res, next) => {
|
|
212
|
+
// Only handle GET requests for non-file routes
|
|
213
|
+
if (req.method !== "GET") {
|
|
214
|
+
next();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
218
|
+
// Skip API routes, health checks, known file extensions, and vite internals
|
|
219
|
+
if (
|
|
220
|
+
req.url.startsWith("/@") ||
|
|
221
|
+
req.url.startsWith("/api") ||
|
|
222
|
+
req.url === "/__health" ||
|
|
223
|
+
/\.[a-z0-9]+$/i.test(req.url) // Has file extension
|
|
224
|
+
) {
|
|
225
|
+
next();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
// Check if local index.html exists, otherwise use toolkit version
|
|
230
|
+
const localIndexPath = path.join(process.cwd(), "index.html");
|
|
231
|
+
const toolkitIndexPath = path.join(runtimeDir, "index.html");
|
|
232
|
+
const indexPath = fs.existsSync(localIndexPath) ? localIndexPath : toolkitIndexPath;
|
|
233
|
+
|
|
234
|
+
if (fs.existsSync(indexPath)) {
|
|
235
|
+
server
|
|
236
|
+
.transformIndexHtml(req.url, fs.readFileSync(indexPath, "utf-8"))
|
|
237
|
+
.then((html) => {
|
|
238
|
+
res.setHeader("Content-Type", "text/html");
|
|
239
|
+
res.end(html);
|
|
240
|
+
})
|
|
241
|
+
.catch((err) => {
|
|
242
|
+
console.error("Error serving SPA fallback:", err);
|
|
243
|
+
next(err);
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
next();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
249
|
};
|
|
250
250
|
},
|
|
251
251
|
},
|