From 91cf6a05863a0e7b7d5d72efe8a8e33dcb8f1f34 Mon Sep 17 00:00:00 2001 From: Sandro Pereira <38382721+54nd10@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:39:19 +0200 Subject: [PATCH] [config] Split config into client and server --- .env.example | 4 ++-- config.ts | 6 ------ configs/client.ts | 3 +++ configs/server.ts | 4 ++++ src/pages/about/team-members/[slug].tsx | 2 +- src/pages/blog/[article].tsx | 2 +- src/pages/services/[service].tsx | 2 +- src/pages/solutions/[solution].tsx | 2 +- src/utils/cms/endpoints.tsx | 2 +- src/utils/hubspot.ts | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 config.ts create mode 100644 configs/client.ts create mode 100644 configs/server.ts diff --git a/.env.example b/.env.example index 9d58aedb..af56cbc0 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ NEXT_PUBLIC_HUBSPOT_API= -NEXT_PUBLIC_STRAPI_API_URL= -NEXT_PUBLIC_STRAPI_API_TOKEN= +STRAPI_API_URL= +STRAPI_API_TOKEN= diff --git a/config.ts b/config.ts deleted file mode 100644 index dc2719ce..00000000 --- a/config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {Fetcher} from '@/models/fetcher.model' -export const hubspotAPI = process.env.NEXT_PUBLIC_HUBSPOT_API || '' -export const strapiAPI = process.env.NEXT_PUBLIC_STRAPI_API_URL || '' -export const strapiAPIToken = process.env.NEXT_PUBLIC_STRAPI_API_TOKEN || '' -export const hubspotFetcher = new Fetcher(hubspotAPI) -export const strapiFetcher = new Fetcher(strapiAPI, {headers: {Authorization: `Bearer ${strapiAPIToken}`}}) diff --git a/configs/client.ts b/configs/client.ts new file mode 100644 index 00000000..0137b102 --- /dev/null +++ b/configs/client.ts @@ -0,0 +1,3 @@ +import {Fetcher} from '@/models/fetcher.model' +export const hubspotAPI = process.env.NEXT_PUBLIC_HUBSPOT_API || '' +export const hubspotFetcher = new Fetcher(hubspotAPI) diff --git a/configs/server.ts b/configs/server.ts new file mode 100644 index 00000000..ec93f0a4 --- /dev/null +++ b/configs/server.ts @@ -0,0 +1,4 @@ +import {Fetcher} from '@/models/fetcher.model' +export const strapiAPI = process.env.STRAPI_API_URL || '' +export const strapiAPIToken = process.env.STRAPI_API_TOKEN || '' +export const strapiFetcher = new Fetcher(strapiAPI, {headers: {Authorization: `Bearer ${strapiAPIToken}`}}) diff --git a/src/pages/about/team-members/[slug].tsx b/src/pages/about/team-members/[slug].tsx index d9a3a7a1..e8c01e9c 100644 --- a/src/pages/about/team-members/[slug].tsx +++ b/src/pages/about/team-members/[slug].tsx @@ -3,7 +3,7 @@ import {PageProps} from '@/models/page.mode' import {TeamMember} from '@/models/team-member' import {getPageProps} from '@/utils/cms/endpoints' import {pageRenderer} from '@/utils/cms/renderer/components' -import {strapiFetcher} from '../../../../config' +import {strapiFetcher} from '../../../../configs/server' export default function BlogPage({components, openGraph}: PageProps) { return pageRenderer(components, openGraph, 'CenteredLayout') diff --git a/src/pages/blog/[article].tsx b/src/pages/blog/[article].tsx index b78bf9f6..e40537d4 100644 --- a/src/pages/blog/[article].tsx +++ b/src/pages/blog/[article].tsx @@ -3,7 +3,7 @@ import {GetStaticPropsContext} from 'next' import {PageProps} from '@/models/page.mode' import {getPageProps} from '@/utils/cms/endpoints' import {pageRenderer} from '@/utils/cms/renderer/components' -import {strapiFetcher} from '../../../config' +import {strapiFetcher} from '../../../configs/server' export default function BlogPage({components, openGraph}: PageProps) { return pageRenderer(components, openGraph, 'CenteredLayout') diff --git a/src/pages/services/[service].tsx b/src/pages/services/[service].tsx index 2786e064..461c41a4 100644 --- a/src/pages/services/[service].tsx +++ b/src/pages/services/[service].tsx @@ -3,7 +3,7 @@ import {PageProps} from '@/models/page.mode' import {Service} from '@/models/service.model' import {getPageProps} from '@/utils/cms/endpoints' import {pageRenderer} from '@/utils/cms/renderer/components' -import {strapiFetcher} from '../../../config' +import {strapiFetcher} from '../../../configs/server' export default function ServicePage({layout, components, openGraph}: PageProps) { return pageRenderer(components, openGraph, layout, true) diff --git a/src/pages/solutions/[solution].tsx b/src/pages/solutions/[solution].tsx index 03be7015..28878f8d 100644 --- a/src/pages/solutions/[solution].tsx +++ b/src/pages/solutions/[solution].tsx @@ -3,7 +3,7 @@ import {PageProps} from '@/models/page.mode' import {Solution} from '@/models/solution.model' import {getPageProps} from '@/utils/cms/endpoints' import {pageRenderer} from '@/utils/cms/renderer/components' -import {strapiFetcher} from '../../../config' +import {strapiFetcher} from '../../../configs/server' export default function SolutionPage({layout, components, openGraph}: PageProps) { return pageRenderer(components, openGraph, layout, true) diff --git a/src/utils/cms/endpoints.tsx b/src/utils/cms/endpoints.tsx index 99149edf..3f269b41 100644 --- a/src/utils/cms/endpoints.tsx +++ b/src/utils/cms/endpoints.tsx @@ -2,7 +2,7 @@ import {PageProps} from '@/models/page.mode' import {componentBlueprints} from './renderer/components' import {getPropsFromNestedObjects} from './renderer/parser' import {snakeCaseObjectKeysToCamelCase} from '../toolbox' -import {strapiFetcher} from '../../../config' +import {strapiFetcher} from '../../../configs/server' export async function getPageProps(path='/', lang='en'): Promise { try { diff --git a/src/utils/hubspot.ts b/src/utils/hubspot.ts index 20813dfa..67a4a17c 100644 --- a/src/utils/hubspot.ts +++ b/src/utils/hubspot.ts @@ -1,5 +1,5 @@ import {HsformsPayload} from '../models/contact-us-form-data.model' -import {hubspotFetcher} from '../../config' +import {hubspotFetcher} from '../../configs/client' export const sendEmail = async(data: HsformsPayload) => { return await hubspotFetcher.call({