2023-06-03 21:32:50 +00:00
|
|
|
// import { renderToString as renderToString_ } from '@vue/server-renderer';
|
|
|
|
import { renderToNodeStream } from '@vue/server-renderer';
|
|
|
|
import { escapeInject } from 'vite-plugin-ssr/server';
|
2023-05-28 22:54:17 +00:00
|
|
|
|
|
|
|
import { createApp } from './app';
|
|
|
|
import { useUser } from '../stores/user';
|
|
|
|
import logoUrl from './logo.svg';
|
|
|
|
|
|
|
|
async function render(pageContext) {
|
|
|
|
// See https://vite-plugin-ssr.com/head
|
|
|
|
const { documentProps } = pageContext.exports;
|
|
|
|
const title = (documentProps && documentProps.title) || 'shack';
|
|
|
|
const desc = (documentProps && documentProps.description) || 'Shack';
|
|
|
|
|
2023-06-03 21:32:50 +00:00
|
|
|
const { app, store } = createApp(pageContext);
|
|
|
|
const stream = renderToNodeStream(app);
|
|
|
|
|
2023-05-28 22:54:17 +00:00
|
|
|
const documentHtml = escapeInject`
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<link rel="icon" href="${logoUrl}" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<meta name="description" content="${desc}" />
|
|
|
|
<title>${title}</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
2023-06-03 21:32:50 +00:00
|
|
|
<div id="app">${stream}</div>
|
2023-05-28 22:54:17 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
const userStore = useUser();
|
|
|
|
|
|
|
|
userStore.user = pageContext.session.user;
|
|
|
|
|
|
|
|
return {
|
2023-06-03 21:32:50 +00:00
|
|
|
documentHtml,
|
2023-05-28 22:54:17 +00:00
|
|
|
pageContext: {
|
|
|
|
initialState: store.state.value,
|
2023-06-03 21:32:50 +00:00
|
|
|
enableEagerStreaming: true,
|
2023-05-28 22:54:17 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
render,
|
|
|
|
};
|
|
|
|
|
2023-06-05 23:30:46 +00:00
|
|
|
export const passToClient = ['urlPathname', 'initialState', 'pageData', 'pageProps', 'routeParams'];
|