generated from pascalmartineau/wp-skeleton
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m6s
21 lines
672 B
TypeScript
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>`;
|
|
}
|
|
});
|