Skip to content

Commit

Permalink
initial draft refactoring for no Workers as part of serving SSR builds
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 16, 2023
1 parent 74d3254 commit e13ed68
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,44 @@ async function bundleSsrPages(compilation) {

// TODO need to handle body as a string
// TODO have to do this "manually" until import.meta.url is supported?
// await fs.writeFile(outputUrl, `
// // import { renderToString } from 'wc-compiler';
// import 'wc-compiler/src/dom-shim.js';
// import Page from './_${filename}';

// export async function handler(request) {
// console.log('${JSON.stringify(page)}');

// let initBody = ${body};
// let initHtml = \`${html}\`;

// if (!initBody) {
// const page = new Page();
// await page.connectedCallback();
// // const { html } = await renderToString(new URL(request.url), false);

// initHtml = initHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, page.innerHTML);
// }

// return new Response(initHtml);
// }
// `);

await fs.writeFile(outputUrl, `
// import { renderToString } from 'wc-compiler';
import 'wc-compiler/src/dom-shim.js';
import Page from './_${filename}';
import { renderToString } from 'wc-compiler';
export async function handler(request) {
console.log('${JSON.stringify(page)}');
console.log('${JSON.stringify(page)}');
console.log({ request });
let initBody = ${body};
let initHtml = \`${html}\`;
if (!initBody) {
const page = new Page();
await page.connectedCallback();
// const { html } = await renderToString(new URL(request.url), false);
console.log('serve', new URL(\`./${filename}\`, import.meta.url));
const { html } = await renderToString(new URL(\`./_${filename}\`, import.meta.url), false);
initHtml = initHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, page.innerHTML);
initHtml = initHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, html);
}
return new Response(initHtml);
Expand Down

0 comments on commit e13ed68

Please sign in to comment.