generated from pascalmartineau/wp-skeleton
22 lines
791 B
TypeScript
22 lines
791 B
TypeScript
import { renderToString } from "vue/server-renderer";
|
|
import { createSSRApp, h } from "vue";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { fieldGroupName, ...attrs } = await readBody(event);
|
|
const componentName = fieldGroupName.replace(/^GroupAbstractBuilder(.*)Layout$/, "Section$1");
|
|
try {
|
|
const componentModule = await import(`../../app/components/sections/${componentName}.vue`);
|
|
const app = createSSRApp({
|
|
render() {
|
|
return h(componentModule.default, attrs);
|
|
},
|
|
});
|
|
const html = await renderToString(app);
|
|
return html;
|
|
}
|
|
catch (error) {
|
|
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
|
|
throw createError({ statusCode: 500, statusMessage: "Erreur interne", message });
|
|
}
|
|
});
|