From c9ad781d9eabeb94c0e0f85529646a1e526ce591 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Fri, 14 Jun 2024 13:34:48 -0500 Subject: [PATCH] refactor: rename env vars --- .bin/01-serve.sh | 4 ++-- .bin/02-seed.sh | 4 ++-- .env.example | 4 ++-- .env.local.example | 4 ++-- .github/workflows/playwright.yml | 2 +- apps/bootstrap/src/client.mjs | 6 +++--- apps/nextjs/playwright.config.ts | 3 ++- apps/nextjs/src/types/env.d.ts | 6 +++--- docker-compose.yml | 4 ++-- libs/backend/src/application/clients/mongo.client.ts | 4 ++-- .../src/application/services/get-celebrities.service.ts | 2 +- .../src/application/services/update-vote.service.ts | 2 +- turbo.json | 2 +- 13 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.bin/01-serve.sh b/.bin/01-serve.sh index 9dd5e82..45747fa 100644 --- a/.bin/01-serve.sh +++ b/.bin/01-serve.sh @@ -16,8 +16,8 @@ echo "MONGO_INITDB_USERNAME = ${MONGO_INITDB_USERNAME}" echo "MONGO_INITDB_PASSWORD = ${MONGO_INITDB_PASSWORD}" # Next.js -echo "NEXT_FRONTEND_URL = ${NEXT_FRONTEND_URL}" -echo "NEXT_MONGO_URL = ${NEXT_MONGO_URL}" +echo "NEXT_PUBLIC_FRONTEND_URL = ${NEXT_PUBLIC_FRONTEND_URL}" +echo "MONGO_URL = ${MONGO_URL}" BUILD_VERSION=$(git rev-parse --short HEAD) echo "BUILD_VERSION = ${BUILD_VERSION}" diff --git a/.bin/02-seed.sh b/.bin/02-seed.sh index 48c283d..998b61f 100644 --- a/.bin/02-seed.sh +++ b/.bin/02-seed.sh @@ -7,8 +7,8 @@ set -a . .env.local set +a -echo "NEXT_FRONTEND_URL = ${NEXT_FRONTEND_URL}" -echo "NEXT_MONGO_URL = ${NEXT_MONGO_URL}" +echo "NEXT_PUBLIC_FRONTEND_URL = ${NEXT_PUBLIC_FRONTEND_URL}" +echo "MONGO_URL = ${MONGO_URL}" cd bootstrap/src diff --git a/.env.example b/.env.example index 8b7e135..be4ad37 100644 --- a/.env.example +++ b/.env.example @@ -8,5 +8,5 @@ MONGO_INITDB_USERNAME="ruleOfThumbDbUser" MONGO_INITDB_PASSWORD="ruleOfThumbDbPassword" ## FRONTEND: NextJS connected to the mongo container -NEXT_FRONTEND_URL="http://localhost:3000" -NEXT_MONGO_URL="mongodb://${MONGO_INITDB_USERNAME}:${MONGO_INITDB_PASSWORD}@mongo:27017/${MONGO_INITDB_DATABASE}" +NEXT_PUBLIC_FRONTEND_URL="http://localhost:3000" +MONGO_URL="mongodb://${MONGO_INITDB_USERNAME}:${MONGO_INITDB_PASSWORD}@mongo:27017/${MONGO_INITDB_DATABASE}" diff --git a/.env.local.example b/.env.local.example index d2afbb7..d4d76ac 100644 --- a/.env.local.example +++ b/.env.local.example @@ -17,6 +17,6 @@ ## Then deploy to production using "npm run build" and then "npm start" ## FRONTEND: NextJS connected to a local/remote mongo instance -NEXT_FRONTEND_URL="http://localhost:3000" -NEXT_MONGO_URL="mongodb://ruleOfThumbDbUser:ruleOfThumbDbPassword@localhost:27017/ruleOfThumbDatabase" +NEXT_PUBLIC_FRONTEND_URL="http://localhost:3000" +MONGO_URL="mongodb://ruleOfThumbDbUser:ruleOfThumbDbPassword@localhost:27017/ruleOfThumbDatabase" diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 7b3ea76..2ca84f8 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -42,7 +42,7 @@ jobs: - name: Run Playwright tests run: pnpm test:e2e env: - NEXT_FRONTEND_URL: ${{ github.event.deployment_status.target_url }} + NEXT_PUBLIC_FRONTEND_URL: ${{ github.event.deployment_status.target_url }} - uses: actions/upload-artifact@v4 if: always() diff --git a/apps/bootstrap/src/client.mjs b/apps/bootstrap/src/client.mjs index a25fc6d..d9c109a 100644 --- a/apps/bootstrap/src/client.mjs +++ b/apps/bootstrap/src/client.mjs @@ -7,17 +7,17 @@ let client; export async function getClient() { // Use connect method to connect to the server if (!client) { - let url = process.env.NEXT_MONGO_URL; + let url = process.env.MONGO_URL; if (!url) { throw new Error( - 'Mongo URL is not defined, use NEXT_MONGO_URL environment variable' + 'Mongo URL is not defined, use MONGO_URL environment variable' ); } console.log('starting getClient...', { database: process.env.MONGO_INITDB_DATABASE, - url: process.env.NEXT_MONGO_URL, + url: process.env.MONGO_URL, }); client = new MongoClient(url); diff --git a/apps/nextjs/playwright.config.ts b/apps/nextjs/playwright.config.ts index 89c7ac7..92284eb 100644 --- a/apps/nextjs/playwright.config.ts +++ b/apps/nextjs/playwright.config.ts @@ -11,7 +11,8 @@ import { devices } from '@playwright/test'; const PORT = Number(process.env.PORT) || 3000; // Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port -const BASE_URL = process.env.NEXT_FRONTEND_URL || `http://localhost:${PORT}`; +const BASE_URL = + process.env.NEXT_PUBLIC_FRONTEND_URL || `http://localhost:${PORT}`; /** * See https://playwright.dev/docs/test-configuration. diff --git a/apps/nextjs/src/types/env.d.ts b/apps/nextjs/src/types/env.d.ts index f0207d7..f2c52c6 100644 --- a/apps/nextjs/src/types/env.d.ts +++ b/apps/nextjs/src/types/env.d.ts @@ -1,8 +1,8 @@ declare global { namespace NodeJS { interface ProcessEnv { - readonly NEXT_FRONTEND_URL: string; - readonly NEXT_MONGO_URL: string; + readonly NEXT_PUBLIC_FRONTEND_URL: string; + readonly MONGO_URL: string; readonly LOG_LEVEL?: string; } } @@ -12,7 +12,7 @@ declare global { interface ImportMeta { emv: { - NEXT_FRONTEND_URL: string; + NEXT_PUBLIC_FRONTEND_URL: string; }; } diff --git a/docker-compose.yml b/docker-compose.yml index 00969fa..a773b1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,8 @@ services: env_file: - .env.docker environment: - NEXT_FRONTEND_URL: ${NEXT_FRONTEND_URL:-http://localhost:3000} - NEXT_MONGO_URL: ${NEXT_MONGO_URL:-mongodb://mongo:27017/ruleOfThumb} + NEXT_PUBLIC_FRONTEND_URL: ${NEXT_PUBLIC_FRONTEND_URL:-http://localhost:3000} + MONGO_URL: ${MONGO_URL:-mongodb://mongo:27017/ruleOfThumb} networks: - nextjs-network ports: diff --git a/libs/backend/src/application/clients/mongo.client.ts b/libs/backend/src/application/clients/mongo.client.ts index 4a3b031..da1141d 100644 --- a/libs/backend/src/application/clients/mongo.client.ts +++ b/libs/backend/src/application/clients/mongo.client.ts @@ -15,7 +15,7 @@ let client: MongoClient; const collection: Record = {}; const bucket: Record = {}; -const mongoDbUrl = process.env.NEXT_MONGO_URL; +const mongoDbUrl = process.env.MONGO_URL; export async function getMongoClient(options?: MongoClientOptions) { // Connection URL @@ -24,7 +24,7 @@ export async function getMongoClient(options?: MongoClientOptions) { if (!client) { if (!mongoDbUrl) { throw new Error( - 'Mongo URL is not defined, use NEXT_MONGO_URL environment variable' + 'Mongo URL is not defined, use MONGO_URL environment variable' ); } diff --git a/libs/frontend/src/application/services/get-celebrities.service.ts b/libs/frontend/src/application/services/get-celebrities.service.ts index 1c326bd..59a1bd5 100644 --- a/libs/frontend/src/application/services/get-celebrities.service.ts +++ b/libs/frontend/src/application/services/get-celebrities.service.ts @@ -2,7 +2,7 @@ import type { CelebritiesType } from '@libs/shared'; export async function getCelebritiesService(): Promise { const response = await fetch( - new URL('/api/celebrities', process.env.NEXT_PUBLIC_PUBLIC_URL) + new URL('/api/celebrities', process.env.NEXT_PUBLIC_FRONTEND_URL) ); if (!response.ok) { diff --git a/libs/frontend/src/application/services/update-vote.service.ts b/libs/frontend/src/application/services/update-vote.service.ts index 6f6a3dc..1400be7 100644 --- a/libs/frontend/src/application/services/update-vote.service.ts +++ b/libs/frontend/src/application/services/update-vote.service.ts @@ -11,7 +11,7 @@ export async function updateVoteService({ const response = await fetch( new URL( `/api/celebrities/${celebrityId}`, - process.env.NEXT_PUBLIC_PUBLIC_URL + process.env.NEXT_PUBLIC_FRONTEND_URL ), { method: 'PATCH', diff --git a/turbo.json b/turbo.json index a02cb83..fa30075 100644 --- a/turbo.json +++ b/turbo.json @@ -1,6 +1,6 @@ { "$schema": "https://turbo.build/schema.json", - "globalEnv": ["LOG_LEVEL"], + "globalEnv": ["LOG_LEVEL", "MONGO_URL", "NEXT_PUBLIC_FRONTEND_URL"], "pipeline": { "dev": { "cache": false,