@gxp-dev/tools 2.0.59 → 2.0.61
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 +46 -0
package/package.json
CHANGED
package/template/vite.config.js
CHANGED
|
@@ -203,6 +203,52 @@ export default defineConfig(({ mode }) => {
|
|
|
203
203
|
include: ["src/**"],
|
|
204
204
|
}
|
|
205
205
|
),
|
|
206
|
+
// Add this new plugin to the plugins array
|
|
207
|
+
{
|
|
208
|
+
name: "spa-fallback",
|
|
209
|
+
configureServer(server) {
|
|
210
|
+
return () => {
|
|
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
|
+
|
|
218
|
+
// Skip API routes, health checks, and known file extensions
|
|
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
|
+
|
|
229
|
+
// Serve index.html for all other routes (SPA fallback)
|
|
230
|
+
const indexPath = path.join(process.cwd(), "index.html");
|
|
231
|
+
if (fs.existsSync(indexPath)) {
|
|
232
|
+
server
|
|
233
|
+
.transformIndexHtml(
|
|
234
|
+
req.url,
|
|
235
|
+
fs.readFileSync(indexPath, "utf-8")
|
|
236
|
+
)
|
|
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
|
+
};
|
|
250
|
+
},
|
|
251
|
+
},
|
|
206
252
|
// Custom request logging and CORS plugin
|
|
207
253
|
{
|
|
208
254
|
name: "request-logger-cors",
|