From 4562df70c46433f6bb00d94fbb3c2523aa58ee77 Mon Sep 17 00:00:00 2001 From: Pagebakers Date: Sat, 4 Nov 2023 18:37:45 +0100 Subject: [PATCH] chore: last try --- apps/website/src/data/blocks/components.ts | 13 +++++-------- .../src/pages/api/blocks/[category]/[component].tsx | 6 +++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/website/src/data/blocks/components.ts b/apps/website/src/data/blocks/components.ts index b68b2f149..88cee4a64 100644 --- a/apps/website/src/data/blocks/components.ts +++ b/apps/website/src/data/blocks/components.ts @@ -59,12 +59,9 @@ function getComponentCode(componentFolder: string, componentName: string) { } const getRootFolder = () => { - return ( - process.env.TEMPLATE_ROOT ?? - path.join( - process.env.PROJECT_CWD ?? __dirname + '/../../../../', - '/packages/pro/saas-ui/templates/src' - ) + return path.join( + process.env.PROJECT_CWD ?? __dirname + '/../../../../', + '/packages/pro/saas-ui/templates/src' ) } @@ -111,9 +108,9 @@ export function getAllComponents(): ComponentInfo[] { export function getComponent( categoryName: string, - componentName: string + componentName: string, + rootFolder = getRootFolder() ): ComponentInfo | null { - const rootFolder = getRootFolder() const componentDirectory = path.join(rootFolder, categoryName, componentName) const componentAttributes = path.join(componentDirectory, 'attributes.json') diff --git a/apps/website/src/pages/api/blocks/[category]/[component].tsx b/apps/website/src/pages/api/blocks/[category]/[component].tsx index b0fb0fcb6..5ace180fe 100644 --- a/apps/website/src/pages/api/blocks/[category]/[component].tsx +++ b/apps/website/src/pages/api/blocks/[category]/[component].tsx @@ -32,7 +32,11 @@ export default async function handler( return res.status(404).json({ error: 'Missing component name' }) } - const attributes = getComponent(categoryName, componentName) + const attributes = getComponent( + categoryName, + componentName, + process.env.TEMPLATE_ROOT + ) if ((!attributes?.attributes.public && !data.session) || error) { return res.status(401).json({ error: 'Unauthorized' })