0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-22 11:08:10 +00:00

stable in prod

This commit is contained in:
Víctor Losada Hernández
2026-02-01 21:31:21 +01:00
parent b4ec26a29f
commit 71bc95251c
3 changed files with 10 additions and 25 deletions

View File

@@ -2,18 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual"
/>
content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" />
<link
href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700"
rel="stylesheet"
type="text/css"
/>
type="text/css" />
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
<!-- Optional: static OG defaults -->

View File

@@ -10,7 +10,7 @@ async function start() {
if (!isProd) {
vite = await createViteServer({
server: { middlewareMode: true },
server: { middlewareMode: 'html' },
appType: "custom",
});
@@ -23,7 +23,7 @@ async function start() {
const app = await createApp(vite);
const PORT = process.env.PORT || config.get("web_port") || 8000;
const PORT = process.env.PORT || config.get("web_port") || 3000;
app.listen(PORT, () => {
const reset = "\x1b[0m"; // Reset to default style
const bright = "\x1b[1m"; // Bright (bold) style

View File

@@ -542,12 +542,6 @@ 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)=>{
if(!req.route) return res.redirect('/'); // Catch-all for invalid routes
@@ -559,7 +553,7 @@ export default async function createApp(vite) {
//Render the page
const renderPage = async (req, res)=>{
console.log('renderpage');
// Create configuration object
const configuration = {
local : isLocalEnvironment,
@@ -579,20 +573,16 @@ export default async function createApp(vite) {
ogMeta : req.ogMeta,
userThemes : req.userThemes
};
console.log('props: ',!!props);
return await renderSPA(req, props);
};
const renderSPA = async (req, props)=>{
console.log('props: ', !!props);
const htmlPath = isProd ? path.resolve('build', 'index.html') : path.resolve('index.html');
let html = fs.readFileSync(htmlPath, 'utf-8');
if(!isProd && vite?.transformIndexHtml) {
html = await vite.transformIndexHtml(req.originalUrl, html);
}
html = html.replace(
'<head>',
`<head><script>window.__INITIAL_PROPS__ = ${JSON.stringify(props)}</script>`
'<head>',
`<head><script>window.__INITIAL_PROPS__ = ${JSON.stringify(props)}</script>`
);
console.log('html', html);