Skip to content

Commit

Permalink
refactor: rename env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgevrgs committed Jun 14, 2024
1 parent ba2a2da commit c9ad781
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .bin/01-serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions .bin/02-seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
4 changes: 2 additions & 2 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"

2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions apps/bootstrap/src/client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
Expand All @@ -12,7 +12,7 @@ declare global {

interface ImportMeta {
emv: {
NEXT_FRONTEND_URL: string;
NEXT_PUBLIC_FRONTEND_URL: string;
};
}

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions libs/backend/src/application/clients/mongo.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let client: MongoClient;
const collection: Record<string, unknown> = {};
const bucket: Record<string, GridFSBucket> = {};

const mongoDbUrl = process.env.NEXT_MONGO_URL;
const mongoDbUrl = process.env.MONGO_URL;

export async function getMongoClient(options?: MongoClientOptions) {
// Connection URL
Expand All @@ -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'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CelebritiesType } from '@libs/shared';

export async function getCelebritiesService(): Promise<CelebritiesType> {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit c9ad781

Please sign in to comment.