aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-03-04 16:49:41 +0100
committerArmand Philippot <git@armandphilippot.com>2022-03-04 16:49:41 +0100
commit4ed70beabc73dd9aa1d2e06ab5902ded0801c404 (patch)
tree05fb731e5c937be885c6d03f31f40f1f9fd2cf8c /src
parent4378c4553b17d5435b08387d80377bce666dc838 (diff)
chore: use a different configuration depending on app env
It will be useful with Docker. Instead of cloning the project with a different configuration, I can manage two different configuration thanks to dotenv and some checking inside the app.
Diffstat (limited to 'src')
-rw-r--r--src/services/graphql/api.ts3
-rw-r--r--src/utils/config.ts12
-rw-r--r--src/utils/helpers/rss.ts13
3 files changed, 19 insertions, 9 deletions
diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts
index 33cc89a..a5be026 100644
--- a/src/services/graphql/api.ts
+++ b/src/services/graphql/api.ts
@@ -1,8 +1,9 @@
import { RequestType, VariablesType } from '@ts/types/app';
+import { settings } from '@utils/config';
import { GraphQLClient } from 'graphql-request';
export const getGraphQLClient = (): GraphQLClient => {
- const apiUrl: string = process.env.NEXT_PUBLIC_GRAPHQL_API || '';
+ const apiUrl = settings.api.url;
if (!apiUrl) throw new Error('API URL not defined.');
diff --git a/src/utils/config.ts b/src/utils/config.ts
index 5928f02..874a24c 100644
--- a/src/utils/config.ts
+++ b/src/utils/config.ts
@@ -1,9 +1,16 @@
+const isStaging = process.env.NEXT_PUBLIC_APP_ENV === 'staging';
+
export const settings = {
ackee: {
filename: process.env.NEXT_PUBLIC_ACKEE_FILENAME || 'tracker.js',
siteId: process.env.NEXT_PUBLIC_ACKEE_SITE_ID || '',
url: `https://${process.env.NEXT_PUBLIC_ACKEE_DOMAIN}` || '',
},
+ api: {
+ url: isStaging
+ ? process.env.NEXT_PUBLIC_STAGING_GRAPHQL_API
+ : process.env.NEXT_PUBLIC_GRAPHQL_API,
+ },
name: 'Armand Philippot',
baseline: {
en: 'Front-end developer',
@@ -20,5 +27,8 @@ export const settings = {
},
postsPerPage: 10,
twitterId: '@ArmandPhilippot',
- url: `${process.env.NEXT_PUBLIC_APP_PROTOCOL}://${process.env.NEXT_PUBLIC_APP_DOMAIN}`,
+ url:
+ (isStaging
+ ? process.env.NEXT_PUBLIC_STAGING_APP_URL
+ : process.env.NEXT_PUBLIC_APP_URL) || '',
};
diff --git a/src/utils/helpers/rss.ts b/src/utils/helpers/rss.ts
index e10c7f3..10a8e77 100644
--- a/src/utils/helpers/rss.ts
+++ b/src/utils/helpers/rss.ts
@@ -15,11 +15,10 @@ const getAllPosts = async (): Promise<ArticlePreview[]> => {
};
export const generateFeed = async () => {
- const websiteUrl = `${process.env.NEXT_PUBLIC_APP_PROTOCOL}://${process.env.NEXT_PUBLIC_APP_DOMAIN}`;
const author = {
name: settings.name,
email: process.env.APP_AUTHOR_EMAIL,
- link: websiteUrl,
+ link: settings.url,
};
const copyright = `${settings.name} CC BY SA ${settings.copyright.startYear} - ${settings.copyright.endYear}`;
const title = `${settings.name} | ${settings.baseline.fr}`;
@@ -29,13 +28,13 @@ export const generateFeed = async () => {
copyright,
description: process.env.APP_FEED_DESCRIPTION,
feedLinks: {
- json: `${websiteUrl}/feed/json`,
- atom: `${websiteUrl}/feed/atom`,
+ json: `${settings.url}/feed/json`,
+ atom: `${settings.url}/feed/atom`,
},
generator: 'Feed & NextJS',
- id: websiteUrl,
+ id: settings.url,
language: settings.locales.defaultLocale,
- link: websiteUrl,
+ link: settings.url,
title,
});
@@ -47,7 +46,7 @@ export const generateFeed = async () => {
date: new Date(post.dates.publication),
description: post.intro,
id: post.id,
- link: `${websiteUrl}/article/${post.slug}`,
+ link: `${settings.url}/article/${post.slug}`,
title: post.title,
});
});