From 9f857e55a971bd2671c78a868e6ae0e184e285cc Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 26 Dec 2022 17:12:55 +0300 Subject: [PATCH] remove 'NEXT_PUBLIC_' prefix from variables --- .env | 8 ++++---- apollo.config.js | 2 +- config/schema/env.js | 10 +++++----- config/schema/runtime-config.js | 12 ++++++------ config/urls.ts | 23 +++++++++-------------- next.config.js | 12 +++++------- pages/_document.jsx | 2 +- styles/colors.js | 4 ++-- 8 files changed, 33 insertions(+), 40 deletions(-) diff --git a/.env b/.env index a9311a2..a7d45db 100644 --- a/.env +++ b/.env @@ -1,10 +1,10 @@ ####### COMMON ####### -NEXT_PUBLIC_USE_DEV_COLORS= +USE_DEV_COLORS= ####### USERS ######## USERS_SUPER=["akalinina","vchikalkin"] ####### URLS ######## -NEXT_PUBLIC_URL_GET_USER_DIRECT= -NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT= -NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT= \ No newline at end of file +URL_GET_USER_DIRECT= +URL_CRM_GRAPHQL_DIRECT= +URL_CORE_FINGAP_DIRECT= \ No newline at end of file diff --git a/apollo.config.js b/apollo.config.js index a8179d9..2b50295 100644 --- a/apollo.config.js +++ b/apollo.config.js @@ -3,7 +3,7 @@ module.exports = { client: { service: { name: 'crmgraphql', - url: process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT, + url: process.env.URL_CRM_GRAPHQL_DIRECT, localSchemaFile: './graphql/crm.schema.graphql', }, excludes: ['graphql/**/*'], diff --git a/config/schema/env.js b/config/schema/env.js index b9f87bd..38775f6 100644 --- a/config/schema/env.js +++ b/config/schema/env.js @@ -2,15 +2,15 @@ const { z } = require('zod'); const envSchema = z.object({ - NEXT_PUBLIC_USE_DEV_COLORS: z + USE_DEV_COLORS: z .unknown() .optional() .transform((val) => !!val), PORT: z.string().optional(), - NEXT_PUBLIC_BASE_PATH: z.string().optional().default(''), - NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT: z.string(), - NEXT_PUBLIC_URL_GET_USER_DIRECT: z.string(), - NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT: z.string(), + BASE_PATH: z.string().optional().default(''), + URL_CRM_GRAPHQL_DIRECT: z.string(), + URL_GET_USER_DIRECT: z.string(), + URL_CORE_FINGAP_DIRECT: z.string(), }); module.exports = envSchema; diff --git a/config/schema/runtime-config.js b/config/schema/runtime-config.js index 8f66687..0e77856 100644 --- a/config/schema/runtime-config.js +++ b/config/schema/runtime-config.js @@ -2,16 +2,16 @@ const envSchema = require('./env'); const publicRuntimeConfigSchema = envSchema.pick({ - NEXT_PUBLIC_BASE_PATH: true, - NEXT_PUBLIC_USE_DEV_COLORS: true, + BASE_PATH: true, + USE_DEV_COLORS: true, }); const serverRuntimeConfigSchema = envSchema.pick({ PORT: true, - NEXT_PUBLIC_BASE_PATH: true, - NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT: true, - NEXT_PUBLIC_URL_GET_USER_DIRECT: true, - NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT: true, + BASE_PATH: true, + URL_CRM_GRAPHQL_DIRECT: true, + URL_GET_USER_DIRECT: true, + URL_CORE_FINGAP_DIRECT: true, }); module.exports = { diff --git a/config/urls.ts b/config/urls.ts index 832b7db..2f4cf53 100644 --- a/config/urls.ts +++ b/config/urls.ts @@ -7,31 +7,26 @@ const { serverRuntimeConfig, publicRuntimeConfig } = getConfig(); function getUrls() { if (isServer()) { - const { - NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT, - NEXT_PUBLIC_URL_GET_USER_DIRECT, - NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT, - NEXT_PUBLIC_BASE_PATH, - PORT, - } = serverRuntimeConfigSchema.parse(serverRuntimeConfig); + const { URL_CRM_GRAPHQL_DIRECT, URL_GET_USER_DIRECT, URL_CORE_FINGAP_DIRECT, BASE_PATH, PORT } = + serverRuntimeConfigSchema.parse(serverRuntimeConfig); return { PORT, - BASE_PATH: NEXT_PUBLIC_BASE_PATH, - URL_CRM_GRAPHQL: NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT, - URL_GET_USER: NEXT_PUBLIC_URL_GET_USER_DIRECT, - URL_CORE_FINGAP: NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT, + BASE_PATH, + URL_CRM_GRAPHQL: URL_CRM_GRAPHQL_DIRECT, + URL_GET_USER: URL_GET_USER_DIRECT, + URL_CORE_FINGAP: URL_CORE_FINGAP_DIRECT, }; } - const { NEXT_PUBLIC_BASE_PATH } = publicRuntimeConfigSchema.parse(publicRuntimeConfig); + const { BASE_PATH } = publicRuntimeConfigSchema.parse(publicRuntimeConfig); function withBasePath(url: string) { - return NEXT_PUBLIC_BASE_PATH + url; + return BASE_PATH + url; } return { - BASE_PATH: NEXT_PUBLIC_BASE_PATH, + BASE_PATH, URL_CRM_GRAPHQL: withBasePath(urls.URL_CRM_GRAPHQL_PROXY), URL_GET_USER: withBasePath(urls.URL_GET_USER_PROXY), URL_CORE_FINGAP: withBasePath(urls.URL_CORE_FINGAP_PROXY), diff --git a/next.config.js b/next.config.js index 1408633..2b56d6b 100644 --- a/next.config.js +++ b/next.config.js @@ -14,7 +14,7 @@ const env = envSchema.parse(process.env); /** @type {import('next').NextConfig} */ const nextConfig = { - basePath: process.env.NEXT_PUBLIC_BASE_PATH, + basePath: process.env.BASE_PATH, output: 'standalone', swcMinify: true, reactStrictMode: true, @@ -31,15 +31,15 @@ const nextConfig = { return [ { source: urls.URL_CRM_GRAPHQL_PROXY, - destination: env.NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT, + destination: env.URL_CRM_GRAPHQL_DIRECT, }, { source: urls.URL_GET_USER_PROXY, - destination: env.NEXT_PUBLIC_URL_GET_USER_DIRECT, + destination: env.URL_GET_USER_DIRECT, }, { source: urls.URL_CORE_FINGAP_PROXY, - destination: env.NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT, + destination: env.URL_CORE_FINGAP_DIRECT, }, ]; }, @@ -49,9 +49,7 @@ const nextConfig = { const plugins = [withLess, withGraphQL]; -const colorPrimary = env.NEXT_PUBLIC_USE_DEV_COLORS - ? COLORS_DEV.COLOR_PRIMARY - : COLORS_PROD.COLOR_PRIMARY; +const colorPrimary = env.USE_DEV_COLORS ? COLORS_DEV.COLOR_PRIMARY : COLORS_PROD.COLOR_PRIMARY; const config = { ...nextConfig, diff --git a/pages/_document.jsx b/pages/_document.jsx index ef528a8..d6f2863 100644 --- a/pages/_document.jsx +++ b/pages/_document.jsx @@ -35,7 +35,7 @@ export default class MyDocument extends Document { - + diff --git a/styles/colors.js b/styles/colors.js index 49dc3f8..0cef3bb 100644 --- a/styles/colors.js +++ b/styles/colors.js @@ -3,10 +3,10 @@ import { publicRuntimeConfigSchema } from '../config/schema/runtime-config'; import { COLORS_DEV, COLORS_PROD } from '../constants/colors'; const { publicRuntimeConfig } = getConfig(); -const { NEXT_PUBLIC_USE_DEV_COLORS } = publicRuntimeConfigSchema.parse(publicRuntimeConfig); +const { USE_DEV_COLORS } = publicRuntimeConfigSchema.parse(publicRuntimeConfig); export default function getColors() { - if (NEXT_PUBLIC_USE_DEV_COLORS) { + if (USE_DEV_COLORS) { return COLORS_DEV; }