diff --git a/client/homebrew/main.jsx b/client/homebrew/main.jsx index baabbf472..e03862604 100644 --- a/client/homebrew/main.jsx +++ b/client/homebrew/main.jsx @@ -2,6 +2,6 @@ import { createRoot } from "react-dom/client"; import Homebrew from "./homebrew.jsx"; const props = window.__INITIAL_PROPS__ || {}; -console.log('props: ', window.__INITIAL_PROPS__); +window.onload = ()=> {console.log('props: ', window.__INITIAL_PROPS__)}; createRoot(document.getElementById("reactRoot")).render(); diff --git a/server/app.js b/server/app.js index 926e3d3ba..86c98bac8 100644 --- a/server/app.js +++ b/server/app.js @@ -542,10 +542,15 @@ export default async function createApp(vite) { return next(); })); + app.use((req, res, next) => { + console.log('Before SPA middleware:', req.originalUrl); + next(); + }); + + //Send rendered page app.use(asyncHandler(async (req, res, next)=>{ - console.log(req.route); - //if(!req.route) return res.redirect('/'); // Catch-all for invalid routes + if(!req.route) return res.redirect('/'); // Catch-all for invalid routes const page = await renderPage(req, res); if(!page) return; @@ -555,7 +560,7 @@ export default async function createApp(vite) { //Render the page const renderPage = async (req, res)=>{ console.log('renderpage'); - // Create configuration object + // Create configuration object const configuration = { local : isLocalEnvironment, publicUrl : config.get('publicUrl') ?? '', @@ -574,24 +579,23 @@ export default async function createApp(vite) { ogMeta : req.ogMeta, userThemes : req.userThemes }; - console.log('props: ',props); + console.log('props: ',!!props); return await renderSPA(req, props); }; const renderSPA = async (req, props)=>{ const htmlPath = isProd ? path.resolve('build', 'index.html') : path.resolve('index.html'); let html = fs.readFileSync(htmlPath, 'utf-8'); - console.log('index.html snippet:', html.slice(0, 200)); // see the first 200 chars - html = html.replace( - '', - `\n` - ); if(!isProd && vite?.transformIndexHtml) { - console.log('transforming'); - return await vite.transformIndexHtml(req.originalUrl, html); + html = await vite.transformIndexHtml(req.originalUrl, html); } + html = html.replace( + '', + `` + ); + console.log('html', html); return html; };