Refactor Docker Compose configuration by removing the igny8_marketing service and updating the marketing dev server setup. Enhance Vite configuration to improve SPA routing for the marketing site, serving marketing.html for all non-static asset requests.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-14 11:18:40 +00:00
parent ae1cc8dcfb
commit 97546aa39b
2 changed files with 34 additions and 27 deletions

View File

@@ -40,18 +40,42 @@ const bypassHostCheck = () => {
};
};
// Plugin to serve marketing.html at root for marketing dev server
const serveMarketingAtRoot = () => {
// Plugin to serve marketing.html for SPA routing in marketing dev server
const serveMarketingSPA = () => {
return {
name: 'serve-marketing-at-root',
name: 'serve-marketing-spa',
configureServer(server) {
server.middlewares.use((req, res, next) => {
// If on port 5174 and requesting root, serve marketing.html
if (server.config.server.port === 5174 && req.url === '/') {
const isMarketingDev = server.config.server.port === 5174;
if (isMarketingDev) {
// Handle SPA routing: serve marketing.html for all routes that don't match actual files
server.middlewares.use((req, res, next) => {
const url = req.url?.split('?')[0] || '/'; // Remove query string
// Skip for Vite internal paths and static assets
if (
url.startsWith('/@') || // Vite internal (@vite/client, @fs, etc.)
url.startsWith('/node_modules') || // Node modules
url.startsWith('/src') || // Source files
url.startsWith('/api') || // API calls
url === '/marketing.html' // Already the marketing HTML
) {
return next();
}
// Check if URL has a file extension (static asset)
const hasFileExtension = /\.\w+$/.test(url);
if (hasFileExtension) {
return next(); // Let Vite handle static assets
}
// For all route-like paths (no extension), serve marketing.html
// This enables SPA routing for direct URL access (e.g., /product, /pricing)
// and browser back/forward navigation
req.url = '/marketing.html';
}
next();
});
next();
});
}
}
};
};
@@ -71,7 +95,7 @@ export default defineConfig(({ mode, command }) => {
publicDir: "public",
plugins: [
bypassHostCheck(), // Workaround for Vite 6.1.0 host check bug
...(process.env.PORT === "5174" || process.argv.includes("--port") && process.argv[process.argv.indexOf("--port") + 1] === "5174" ? [serveMarketingAtRoot()] : []),
...(process.env.PORT === "5174" || process.argv.includes("--port") && process.argv[process.argv.indexOf("--port") + 1] === "5174" ? [serveMarketingSPA()] : []),
react(),
svgr({
svgrOptions: {