Files
cultureat-bak/wp-content/themes/ccat/server/api/preview.post.ts

22 lines
671 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);
const app = createSSRApp({
render() {
return 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>`;
}
});