Files
cultureat-bak/wp-content/themes/ccat/server/api/preview.post.ts
Pascal Martineau e041408715
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 58s
refactor: fieldGroupName => __typename
2025-09-25 15:30:10 -04:00

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>`;
}
});