Files
cultureat-bak/wp-content/themes/ccat/server/api/preview.post.ts
Pascal Martineau 5ce55b5c33
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m6s
refactor: sections-map
2025-09-24 14:05:47 -04:00

21 lines
672 B
TypeScript

import { renderToString } from "vue/server-renderer";
import { createSSRApp, h } from "vue";
import type { TheSectionFragment } from "#graphql-operations";
export default defineEventHandler(async (event) => {
const { fieldGroupName, ...attrs } = await readBody<TheSectionFragment>(event);
try {
const app = createSSRApp({
render() {
return h(sectionsMap[fieldGroupName as FieldGroupName], 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>`;
}
});