From 98a3103cc90ceeb2d753816bdadd4a8a75c55777 Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 4 Nov 2023 14:55:19 -0700 Subject: [PATCH] Setup different dev/prod mongo databases attempt #2 (#379) * Setup condition to use dev db on local and staging instance * Hopefully fix the node env variable --- .github/workflows/build-and-deploy.yml | 1 + api/src/helpers/mongo.ts | 2 +- api/src/types/environment.d.ts | 2 +- stacks/backend.ts | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 9b9e5710..7d515512 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -44,6 +44,7 @@ jobs: PRODUCTION_DOMAIN: ${{secrets.PRODUCTION_DOMAIN}} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + NODE_ENV: ${{ github.event_name == 'pull_request' && 'staging' || 'production' }} - name: Comment staging URL uses: marocchino/sticky-pull-request-comment@v2 diff --git a/api/src/helpers/mongo.ts b/api/src/helpers/mongo.ts index 4e664b8a..6932dd23 100644 --- a/api/src/helpers/mongo.ts +++ b/api/src/helpers/mongo.ts @@ -12,7 +12,7 @@ const client = new MongoClient(process.env.MONGO_URL, { useNewUrlParser: true, u /** * Database name to use in mongo */ -const DB_NAME = 'peterPortalDB'; +const DB_NAME = process.env.NODE_ENV == 'production' ? 'peterPortalDB' : 'peterPortalDevDB'; /** * Collection names that we are using */ diff --git a/api/src/types/environment.d.ts b/api/src/types/environment.d.ts index 1d3f3a8c..5f7311b0 100644 --- a/api/src/types/environment.d.ts +++ b/api/src/types/environment.d.ts @@ -5,7 +5,7 @@ declare global { */ interface ProcessEnv { MONGO_URL: string; - NODE_ENV: 'development' | 'production'; + NODE_ENV: 'development' | 'production' | 'staging'; PORT?: string; PUBLIC_API_URL: string; PUBLIC_API_GRAPHQL_URL: string; diff --git a/stacks/backend.ts b/stacks/backend.ts index 49254430..8aa90fb2 100644 --- a/stacks/backend.ts +++ b/stacks/backend.ts @@ -40,7 +40,8 @@ export function BackendStack({app, stack}: StackContext) { GOOGLE_CLIENT: process.env.GOOGLE_CLIENT, GOOGLE_SECRET: process.env.GOOGLE_SECRET, PRODUCTION_DOMAIN: process.env.PRODUCTION_DOMAIN, - ADMIN_EMAILS: process.env.ADMIN_EMAILS + ADMIN_EMAILS: process.env.ADMIN_EMAILS, + NODE_ENV: process.env.NODE_ENV } } },