generated from pascalmartineau/wp-skeleton
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 58s
19 lines
698 B
TypeScript
19 lines
698 B
TypeScript
import { renderToString } from "vue/server-renderer";
|
|
import { createSSRApp, h } from "vue";
|
|
import type { TheSectionFragment } from "#graphql-operations";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const section = await readBody<TheSectionFragment>(event);
|
|
const { component, attrs } = useSection(section);
|
|
// @ts-expect-error Properties from TheSectionFragment
|
|
const app = createSSRApp({ render: () => h(component, attrs) });
|
|
const html = await renderToString(app);
|
|
return html;
|
|
}
|
|
catch (error) {
|
|
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
|
|
return `<div style="color: red">${message}</div>`;
|
|
}
|
|
});
|