mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
stable in prod
This commit is contained in:
@@ -2,18 +2,13 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
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
|
<link
|
||||||
href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700"
|
href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700"
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css" />
|
||||||
/>
|
|
||||||
|
|
||||||
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
||||||
|
|
||||||
<!-- Optional: static OG defaults -->
|
<!-- Optional: static OG defaults -->
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ async function start() {
|
|||||||
|
|
||||||
if (!isProd) {
|
if (!isProd) {
|
||||||
vite = await createViteServer({
|
vite = await createViteServer({
|
||||||
server: { middlewareMode: true },
|
server: { middlewareMode: 'html' },
|
||||||
appType: "custom",
|
appType: "custom",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ async function start() {
|
|||||||
|
|
||||||
const app = await createApp(vite);
|
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, () => {
|
app.listen(PORT, () => {
|
||||||
const reset = "\x1b[0m"; // Reset to default style
|
const reset = "\x1b[0m"; // Reset to default style
|
||||||
const bright = "\x1b[1m"; // Bright (bold) style
|
const bright = "\x1b[1m"; // Bright (bold) style
|
||||||
|
|||||||
@@ -542,12 +542,6 @@ export default async function createApp(vite) {
|
|||||||
return next();
|
return next();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
|
||||||
console.log('Before SPA middleware:', req.originalUrl);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//Send rendered page
|
//Send rendered page
|
||||||
app.use(asyncHandler(async (req, res, next)=>{
|
app.use(asyncHandler(async (req, res, next)=>{
|
||||||
if(!req.route) return res.redirect('/'); // Catch-all for invalid routes
|
if(!req.route) return res.redirect('/'); // Catch-all for invalid routes
|
||||||
@@ -559,7 +553,7 @@ export default async function createApp(vite) {
|
|||||||
|
|
||||||
//Render the page
|
//Render the page
|
||||||
const renderPage = async (req, res)=>{
|
const renderPage = async (req, res)=>{
|
||||||
console.log('renderpage');
|
|
||||||
// Create configuration object
|
// Create configuration object
|
||||||
const configuration = {
|
const configuration = {
|
||||||
local : isLocalEnvironment,
|
local : isLocalEnvironment,
|
||||||
@@ -579,20 +573,16 @@ export default async function createApp(vite) {
|
|||||||
ogMeta : req.ogMeta,
|
ogMeta : req.ogMeta,
|
||||||
userThemes : req.userThemes
|
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');
|
const htmlPath = isProd ? path.resolve('build', 'index.html') : path.resolve('index.html');
|
||||||
let html = fs.readFileSync(htmlPath, 'utf-8');
|
let html = fs.readFileSync(htmlPath, 'utf-8');
|
||||||
|
|
||||||
if(!isProd && vite?.transformIndexHtml) {
|
|
||||||
html = await vite.transformIndexHtml(req.originalUrl, html);
|
|
||||||
}
|
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
'<head>',
|
'<head>',
|
||||||
`<head><script>window.__INITIAL_PROPS__ = ${JSON.stringify(props)}</script>`
|
`<head><script>window.__INITIAL_PROPS__ = ${JSON.stringify(props)}</script>`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('html', html);
|
console.log('html', html);
|
||||||
|
|||||||
Reference in New Issue
Block a user