From 548e07b84738a3fff9c81dc99d2b0d2831770483 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:09:18 -0800 Subject: [PATCH 01/20] Add firebase hosting with ci --- .firebaserc | 5 ++ .github/workflows/firebase-hosting-merge.yml | 20 +++++ .../firebase-hosting-pull-request.yml | 17 ++++ firebase.json | 10 +++ frontend/public/404.html | 33 +++++++ frontend/public/index.html | 89 +++++++++++++++++++ 6 files changed, 174 insertions(+) create mode 100644 .firebaserc create mode 100644 .github/workflows/firebase-hosting-merge.yml create mode 100644 .github/workflows/firebase-hosting-pull-request.yml create mode 100644 firebase.json create mode 100644 frontend/public/404.html create mode 100644 frontend/public/index.html diff --git a/.firebaserc b/.firebaserc new file mode 100644 index 00000000..4303aa90 --- /dev/null +++ b/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "pia-dev-60cea" + } +} diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml new file mode 100644 index 00000000..746c1f13 --- /dev/null +++ b/.github/workflows/firebase-hosting-merge.yml @@ -0,0 +1,20 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on merge +'on': + push: + branches: + - main +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: '${{ secrets.GITHUB_TOKEN }}' + firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PIA_DEV_60CEA }}' + channelId: live + projectId: pia-dev-60cea diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml new file mode 100644 index 00000000..ee223de5 --- /dev/null +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -0,0 +1,17 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on PR +'on': pull_request +jobs: + build_and_preview: + if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: '${{ secrets.GITHUB_TOKEN }}' + firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PIA_DEV_60CEA }}' + projectId: pia-dev-60cea diff --git a/firebase.json b/firebase.json new file mode 100644 index 00000000..c10916e3 --- /dev/null +++ b/firebase.json @@ -0,0 +1,10 @@ +{ + "hosting": { + "public": "frontend/public", + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ] + } +} diff --git a/frontend/public/404.html b/frontend/public/404.html new file mode 100644 index 00000000..829eda8f --- /dev/null +++ b/frontend/public/404.html @@ -0,0 +1,33 @@ + + + + + + Page Not Found + + + + +
+

404

+

Page Not Found

+

The specified file was not found on this website. Please check the URL for mistakes and try again.

+

Why am I seeing this?

+

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.

+
+ + diff --git a/frontend/public/index.html b/frontend/public/index.html new file mode 100644 index 00000000..db385020 --- /dev/null +++ b/frontend/public/index.html @@ -0,0 +1,89 @@ + + + + + + Welcome to Firebase Hosting + + + + + + + + + + + + + + + + + + + +
+

Welcome

+

Firebase Hosting Setup Complete

+

You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!

+ Open Hosting Documentation +
+

Firebase SDK Loading…

+ + + + From d6c83aa4adf1fcb16a3aa6131331a2f0e54fb3d2 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:11:19 -0800 Subject: [PATCH 02/20] try fixing build --- .github/workflows/firebase-hosting-merge.yml | 2 +- .github/workflows/firebase-hosting-pull-request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml index 746c1f13..4243cec2 100644 --- a/.github/workflows/firebase-hosting-merge.yml +++ b/.github/workflows/firebase-hosting-merge.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: npm ci && npm run build + - run: cd frontend && npm ci && npm run build - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: '${{ secrets.GITHUB_TOKEN }}' diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml index ee223de5..9ebb1a47 100644 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: npm ci && npm run build + - run: cd frontend && npm ci && npm run build - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: '${{ secrets.GITHUB_TOKEN }}' From 884f2594a33c83c28b40a5db3f00e2c2cb811c57 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:20:27 -0800 Subject: [PATCH 03/20] update public directory --- firebase.json | 2 +- frontend/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase.json b/firebase.json index c10916e3..782f71a5 100644 --- a/firebase.json +++ b/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "frontend/public", + "public": "frontend/build", "ignore": [ "firebase.json", "**/.*", diff --git a/frontend/package.json b/frontend/package.json index d95ffef2..4621b648 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build && next export", "start": "next start", "lint": "next lint", "test": "jest", From 9cd42ffae91dfc2bfe8435d46be27552abec8c42 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:24:40 -0800 Subject: [PATCH 04/20] fix next export --- frontend/next.config.js | 4 +++- frontend/package.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/next.config.js b/frontend/next.config.js index 658404ac..a35bfad7 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: "export", +}; module.exports = nextConfig; diff --git a/frontend/package.json b/frontend/package.json index 4621b648..d95ffef2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build && next export", + "build": "next build", "start": "next start", "lint": "next lint", "test": "jest", From 6f0961ff2192482c508069513ddd344660c9aa4c Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:27:11 -0800 Subject: [PATCH 05/20] remove export thing --- frontend/next.config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/next.config.js b/frontend/next.config.js index a35bfad7..658404ac 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,6 +1,4 @@ /** @type {import('next').NextConfig} */ -const nextConfig = { - output: "export", -}; +const nextConfig = {}; module.exports = nextConfig; From fe742d9d9ce43c55e1524404e944c79cd7a6fcad Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:32:10 -0800 Subject: [PATCH 06/20] change to unoptimized images --- frontend/next.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/next.config.js b/frontend/next.config.js index 658404ac..8d7f01b5 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,4 +1,9 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: "export", + images: { + unoptimized: true, + }, +}; module.exports = nextConfig; From 002cd986664d45f3b27d43c6c4b465f3921086f8 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:35:39 -0800 Subject: [PATCH 07/20] change build route --- firebase.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.json b/firebase.json index 782f71a5..f4755549 100644 --- a/firebase.json +++ b/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "frontend/build", + "public": "build", "ignore": [ "firebase.json", "**/.*", From 7adf97269998f8060aaa1488945833e756d20e4a Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:45:26 -0800 Subject: [PATCH 08/20] fix public folder possibly --- firebase.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.json b/firebase.json index f4755549..df8d5d36 100644 --- a/firebase.json +++ b/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "build", + "public": "frontend/.next", "ignore": [ "firebase.json", "**/.*", From 36dbb8ec0dfe427a81813895e64b74734cf81702 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:49:03 -0800 Subject: [PATCH 09/20] remove auto generated index --- frontend/public/404.html | 33 -------------- frontend/public/index.html | 89 -------------------------------------- 2 files changed, 122 deletions(-) delete mode 100644 frontend/public/404.html delete mode 100644 frontend/public/index.html diff --git a/frontend/public/404.html b/frontend/public/404.html deleted file mode 100644 index 829eda8f..00000000 --- a/frontend/public/404.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - Page Not Found - - - - -
-

404

-

Page Not Found

-

The specified file was not found on this website. Please check the URL for mistakes and try again.

-

Why am I seeing this?

-

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.

-
- - diff --git a/frontend/public/index.html b/frontend/public/index.html deleted file mode 100644 index db385020..00000000 --- a/frontend/public/index.html +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - Welcome to Firebase Hosting - - - - - - - - - - - - - - - - - - - -
-

Welcome

-

Firebase Hosting Setup Complete

-

You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!

- Open Hosting Documentation -
-

Firebase SDK Loading…

- - - - From de4cd3885da248c15181cccd4391916ea3e46b39 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:03:39 -0800 Subject: [PATCH 10/20] update public again --- firebase.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.json b/firebase.json index df8d5d36..625e10b8 100644 --- a/firebase.json +++ b/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "frontend/.next", + "public": "frontend/out", "ignore": [ "firebase.json", "**/.*", From d3590666897bf40919d9e2cadc47830c414b843f Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:01:41 -0800 Subject: [PATCH 11/20] firbease backend setup + better yaml --- .firebase/hosting.ZnJvbnRlbmQvb3V0.cache | 29 ++++ .github/workflows/build-and-deploy.yml | 50 ++++++ .github/workflows/firebase-hosting-merge.yml | 20 --- .../firebase-hosting-pull-request.yml | 17 -- .github/workflows/preview-deploy.yml | 13 ++ .github/workflows/staging-deploy.yml | 15 ++ backend/package-lock.json | 163 +++++++++++------- backend/package.json | 9 +- backend/src/app.ts | 18 +- backend/src/routes/api.ts | 12 ++ backend/tsconfig.json | 2 +- firebase.json | 39 +++++ 12 files changed, 279 insertions(+), 108 deletions(-) create mode 100644 .firebase/hosting.ZnJvbnRlbmQvb3V0.cache create mode 100644 .github/workflows/build-and-deploy.yml delete mode 100644 .github/workflows/firebase-hosting-merge.yml delete mode 100644 .github/workflows/firebase-hosting-pull-request.yml create mode 100644 .github/workflows/preview-deploy.yml create mode 100644 .github/workflows/staging-deploy.yml create mode 100644 backend/src/routes/api.ts diff --git a/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache b/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache new file mode 100644 index 00000000..4aa62654 --- /dev/null +++ b/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache @@ -0,0 +1,29 @@ +404.html,1707342729450,1d5d2cf8f79692cf0d5c2931356f4443ae1c0e784894979a2c92e8a712c5b5cd +index.html,1707342729447,d336204a9e548736cf813f5bb2a1c5a50cfaec42da3882f742f4a9274c49910e +next.svg,1707342729341,7b16665552cb47db34db342505d6d340caaf5813ca2cba1df3536ed67ea33f64 +notifications.html,1707342729449,d74f3f879681cb434f9a63453d21d34d4dd71531850353f5f61b69423b0f8bef +profile.html,1707342729449,4a7413e183ac2087061d7134a04f1c2a95f9112fa50b89a340b71acf5cb7cf58 +programs.html,1707342729452,0ad85ff90a9444594199ad9cb8758cd64ce5675bebe12c4af8ae717fed2ff7fe +vercel.svg,1707342729341,ddb9254655f2b7733e1193fb66cb4beb95c29ad752d7adbc1765026e124c88c5 +_next/static/FIIdxkpNmFNQdl9X9GIkT/_buildManifest.js,1707342729293,8906057e4b8aa41a4915e593ca3e0edbcfa9d3d0fd5adce0c2553072b1c3bb29 +_next/static/FIIdxkpNmFNQdl9X9GIkT/_ssgManifest.js,1707342729293,5c126729f9831113842c425975615db312fa26d39f3a9e1baa47d4ad65ac2f90 +_next/static/chunks/726-f707db82ab9098d4.js,1707342729293,0b338021b9f5301fc1a8fc475db5aae677bad5f5b7233b0f9d145ba98d48ecf4 +_next/static/chunks/framework-5429a50ba5373c56.js,1707342729293,cc7c6067a86256348371aeb89094b5e79dde940922de6558a4106fe13e8aab63 +_next/static/chunks/main-18a986b8471251f8.js,1707342729293,556690653af7cdd517cd439de6ddf6713bc9ecbcee390e333950c1f708a1adb7 +_next/static/chunks/polyfills-c67a75d1b6f99dc8.js,1707342729293,9f22ebbc1e5746bc08aa476baa8169d3ac2c27814dba6bf675b749113ac4943e +_next/static/chunks/webpack-5146130448d8adf7.js,1707342729293,76f9a07c08ba535d4656252a7ed86d7ac63a7a28415ffebe6b49c1d935afeb58 +_next/static/chunks/pages/_app-cbe5045bb6357d05.js,1707342729305,f525ac2d60ba758ddb3032b4939f5f7706ca1ae819c53b4f02879e6a2547caa0 +_next/static/chunks/pages/_error-b6491f42fb2263bb.js,1707342729305,4066094c111445f36ac1bdecf026e6a3d1db0ea93016d2c97860cf809ebc18de +_next/static/chunks/pages/index-6b9327b688bd07bd.js,1707342729305,d211d519134ade4ad01e35ec3ae1bf9934db33ed0affe35b600fdd8dce813415 +_next/static/chunks/pages/notifications-663870f95aedf130.js,1707342729305,2a071857ce2428e2d153b0ae928d1b263795a33b83ba14d523cf9f0049124366 +_next/static/chunks/pages/profile-c79e19b2230e2a09.js,1707342729306,eab412cd5f8547b81320f3dbf1a4d3da730213101c0d79bc04ba96a8f06b0119 +_next/static/chunks/pages/programs-8f2c72a07bfd7dd0.js,1707342729306,fad24f7810b4a49f9e26cfa1d0f2e9a22706262bd91527fb55b2113396df3dfa +_next/static/css/6fbe838a02cbc165.css,1707342729293,32b6ded88b74a1374d76738f67757c42cdbad33bfe9b5fcf4750176a74bebbdf +_next/static/css/7a0c8f7af9ca41c1.css,1707342729293,bf0d39db174412348b49c468d8b9c15441aa9d3511b2f5aeee7367e870785b41 +_next/static/media/591327bf3b62a611-s.woff2,1707342729293,945e04767753c910a548dca3cd5165d6d9f8d1b44c4b9a6272733f8d2cb39ddd +_next/static/media/87c72f23c47212b9-s.woff2,1707342729293,2ec4f426325ae4503262191c02f22fa491f63e233f3702be3847e05da80d367e +_next/static/media/916d3686010a8de2-s.p.woff2,1707342729293,3bf0222e823f7658ca78d05a204c5a021659b9a5afa16978b326c5b3608f228b +_next/static/media/916d3686010a8de2-s.woff2,1707342729293,3bf0222e823f7658ca78d05a204c5a021659b9a5afa16978b326c5b3608f228b +_next/static/media/Alternate Gothic No3 D Regular.df419e0a.otf,1707342729293,9164495ebf85803d6a6472eaf3f571364c1fcab3f36bc5eb8b7747019a2ba332 +sidebar/logo.png,1707342729347,45b9b90921e3d04a7ed27fc17ddf9d0cb74809836a36017ba9e70eab48faefd6 +sidebar/nav_menu.svg,1707342729347,40f2ca8d662887e01cb835ee9bf0a7766f41d196d843f342f0d40f79d42b8f57 diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 00000000..1b78f52f --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,50 @@ +name: Build and Deploy + +on: + workflow_call: + inputs: + environment: + required: true + type: string + firebaseProjectId: + required: true + type: string + firebaseHostingChannelId: + required: false + type: string + +jobs: + build_and_preview: + name: Build and Deploy + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Create Frontend .env + run: | + cd frontend + touch .env + echo FIREBASE_CONFIG=${{ secrets.FIREBASE_CONFIG }} >> .env + - name: Create Backend .env + run: | + cd backend + touch .env + echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env + echo SERVICE_ACCOUNT_KEY=${{ secrets.SERVICE_ACCOUNT_KEY }} >> .env + echo FRONTEND_ORIGIN=${{ vars.FRONTEND_ORIGIN }} >> .env + - name: Build Frontend + run: cd frontend && npm ci && npm run build + - name: Build Backend + run: | + cd backend + npm run build + - name: Deploy to Firebase + uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: "${{ secrets.GITHUB_TOKEN }}" + firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" + projectId: ${{ inputs.firebaseProjectId }} + channelId: ${{ inputs.firebaseHostingChannelId }} + env: + FIREBASE_CLI_EXPERIMENTS: pintags \ No newline at end of file diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml deleted file mode 100644 index 4243cec2..00000000 --- a/.github/workflows/firebase-hosting-merge.yml +++ /dev/null @@ -1,20 +0,0 @@ -# This file was auto-generated by the Firebase CLI -# https://github.com/firebase/firebase-tools - -name: Deploy to Firebase Hosting on merge -'on': - push: - branches: - - main -jobs: - build_and_deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: cd frontend && npm ci && npm run build - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: '${{ secrets.GITHUB_TOKEN }}' - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PIA_DEV_60CEA }}' - channelId: live - projectId: pia-dev-60cea diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml deleted file mode 100644 index 9ebb1a47..00000000 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file was auto-generated by the Firebase CLI -# https://github.com/firebase/firebase-tools - -name: Deploy to Firebase Hosting on PR -'on': pull_request -jobs: - build_and_preview: - if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: cd frontend && npm ci && npm run build - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: '${{ secrets.GITHUB_TOKEN }}' - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PIA_DEV_60CEA }}' - projectId: pia-dev-60cea diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml new file mode 100644 index 00000000..6a69384a --- /dev/null +++ b/.github/workflows/preview-deploy.yml @@ -0,0 +1,13 @@ +name: Deploy Branch Preview +on: + pull_request: + +jobs: + deploy_preview: + name: Deploy Branch Preview + if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}" + uses: ./.github/workflows/build-and-deploy.yml + with: + environment: Preview + firebaseProjectId: pia-dev-60cea + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 00000000..d7e55f75 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,15 @@ +name: Deploy to Staging +on: + push: + branches: + - main + +jobs: + deploy_staging: + name: Deploy to Staging + uses: ./.github/workflows/build-and-deploy.yml + with: + environment: Staging + firebaseProjectId: pia-dev-60cea + firebaseHostingChannelId: live + secrets: inherit \ No newline at end of file diff --git a/backend/package-lock.json b/backend/package-lock.json index e41ece62..584d3e17 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -14,8 +14,10 @@ "express": "^4.18.2", "express-validator": "^7.0.1", "firebase-admin": "^12.0.0", + "firebase-functions": "^4.7.0", "mongodb": "^6.3.0", - "mongoose": "^8.0.3" + "mongoose": "^8.0.3", + "tsc-alias": "^1.8.8" }, "devDependencies": { "@types/cors": "^2.8.17", @@ -449,7 +451,6 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -462,7 +463,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, "engines": { "node": ">= 8" } @@ -471,7 +471,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -483,32 +482,27 @@ "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", - "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", - "optional": true + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" }, "node_modules/@protobufjs/base64": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", - "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", - "optional": true + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" }, "node_modules/@protobufjs/codegen": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", - "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==", - "optional": true + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" }, "node_modules/@protobufjs/eventemitter": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", - "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==", - "optional": true + "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" }, "node_modules/@protobufjs/fetch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", - "optional": true, "dependencies": { "@protobufjs/aspromise": "^1.1.1", "@protobufjs/inquire": "^1.1.0" @@ -517,32 +511,27 @@ "node_modules/@protobufjs/float": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", - "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", - "optional": true + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" }, "node_modules/@protobufjs/inquire": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", - "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==", - "optional": true + "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" }, "node_modules/@protobufjs/path": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", - "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", - "optional": true + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" }, "node_modules/@protobufjs/pool": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", - "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", - "optional": true + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" }, "node_modules/@protobufjs/utf8": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", - "optional": true + "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, "node_modules/@tootallnate/once": { "version": "2.0.0", @@ -604,7 +593,6 @@ "version": "2.8.17", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", - "dev": true, "dependencies": { "@types/node": "*" } @@ -1243,7 +1231,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "dev": true, "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -1305,7 +1292,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true, "engines": { "node": ">=8" } @@ -1461,7 +1447,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", - "dev": true, "engines": { "node": ">=8" } @@ -1503,7 +1488,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, "dependencies": { "fill-range": "^7.0.1" }, @@ -1580,7 +1564,6 @@ "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", - "dev": true, "funding": [ { "type": "individual", @@ -1647,6 +1630,14 @@ "node": ">= 0.8" } }, + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/compressible": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", @@ -1812,7 +1803,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, "dependencies": { "path-type": "^4.0.0" }, @@ -2416,7 +2406,6 @@ "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -2466,7 +2455,6 @@ "version": "1.16.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", "integrity": "sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==", - "dev": true, "dependencies": { "reusify": "^1.0.4" } @@ -2498,7 +2486,6 @@ "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, "dependencies": { "to-regex-range": "^5.0.1" }, @@ -2561,6 +2548,38 @@ "@google-cloud/storage": "^7.7.0" } }, + "node_modules/firebase-functions": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.7.0.tgz", + "integrity": "sha512-YgWqA9otWlBUouY4I2yd0vq9SyQdQ6GJxfH7wGJclzS2pzBQHcU5HhE1Vz/xTrWcKJyw8uPN98WtSE9/APUJJg==", + "dependencies": { + "@types/cors": "^2.8.5", + "@types/express": "4.17.3", + "cors": "^2.8.5", + "express": "^4.17.1", + "node-fetch": "^2.6.7", + "protobufjs": "^7.2.2" + }, + "bin": { + "firebase-functions": "lib/bin/firebase-functions.js" + }, + "engines": { + "node": ">=14.10.0" + }, + "peerDependencies": { + "firebase-admin": "^10.0.0 || ^11.0.0 || ^12.0.0" + } + }, + "node_modules/firebase-functions/node_modules/@types/express": { + "version": "4.17.3", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.3.tgz", + "integrity": "sha512-I8cGRJj3pyOLs/HndoP+25vOqhqWkAZsWMEmq1qXy/b/M3ppufecUwaK2/TVDVxcV61/iSdhykUjQQ2DLSrTdg==", + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + }, "node_modules/flat-cache": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", @@ -2645,7 +2664,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "optional": true, "os": [ @@ -2856,7 +2874,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "dependencies": { "is-glob": "^4.0.1" }, @@ -2898,7 +2915,6 @@ "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -3208,7 +3224,6 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", - "dev": true, "engines": { "node": ">= 4" } @@ -3305,7 +3320,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, "dependencies": { "binary-extensions": "^2.0.0" }, @@ -3372,7 +3386,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -3390,7 +3403,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, "dependencies": { "is-extglob": "^2.1.1" }, @@ -3414,7 +3426,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, "engines": { "node": ">=0.12.0" } @@ -3838,8 +3849,7 @@ "node_modules/long": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", - "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", - "optional": true + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, "node_modules/lru-cache": { "version": "6.0.0", @@ -3903,7 +3913,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, "engines": { "node": ">= 8" } @@ -3920,7 +3929,6 @@ "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", - "dev": true, "dependencies": { "braces": "^3.0.2", "picomatch": "^2.3.1" @@ -4203,6 +4211,18 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/mylas": { + "version": "2.1.13", + "resolved": "https://registry.npmjs.org/mylas/-/mylas-2.1.13.tgz", + "integrity": "sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==", + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/raouldeheer" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -4221,7 +4241,6 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "optional": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4240,20 +4259,17 @@ "node_modules/node-fetch/node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "optional": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/node-fetch/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "optional": true + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/node-fetch/node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "optional": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -4271,7 +4287,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -4503,7 +4518,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, "engines": { "node": ">=8" } @@ -4512,7 +4526,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, @@ -4520,6 +4533,17 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/plimit-lit": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/plimit-lit/-/plimit-lit-1.6.1.tgz", + "integrity": "sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==", + "dependencies": { + "queue-lit": "^1.5.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -4561,7 +4585,6 @@ "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", "hasInstallScript": true, - "optional": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", @@ -4619,11 +4642,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/queue-lit": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.2.tgz", + "integrity": "sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==", + "engines": { + "node": ">=12" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, "funding": [ { "type": "github", @@ -4679,7 +4709,6 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", - "dev": true, "dependencies": { "picomatch": "^2.2.1" }, @@ -4790,7 +4819,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" @@ -4812,7 +4840,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, "funding": [ { "type": "github", @@ -5014,7 +5041,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, "engines": { "node": ">=8" } @@ -5282,7 +5308,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "dependencies": { "is-number": "^7.0.0" }, @@ -5407,6 +5432,22 @@ } } }, + "node_modules/tsc-alias": { + "version": "1.8.8", + "resolved": "https://registry.npmjs.org/tsc-alias/-/tsc-alias-1.8.8.tgz", + "integrity": "sha512-OYUOd2wl0H858NvABWr/BoSKNERw3N9GTi3rHPK8Iv4O1UyUXIrTTOAZNHsjlVpXFOhpJBVARI1s+rzwLivN3Q==", + "dependencies": { + "chokidar": "^3.5.3", + "commander": "^9.0.0", + "globby": "^11.0.4", + "mylas": "^2.1.9", + "normalize-path": "^3.0.0", + "plimit-lit": "^1.2.6" + }, + "bin": { + "tsc-alias": "dist/bin/index.js" + } + }, "node_modules/tsconfig": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-7.0.0.tgz", diff --git a/backend/package.json b/backend/package.json index c5ad2caf..f4c73b9b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,14 +2,15 @@ "name": "backend", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "dist/app.js", "scripts": { "dev": "npx ts-node-dev src/app.ts", + "build": "tsc && tsc-alias", "format": "npm run check-git-hooks && prettier --write .", "lint-fix": "npm run check-git-hooks && (eslint --fix --cache --report-unused-disable-directives . || true) && prettier --write .", "lint-check": "npm run check-git-hooks && eslint --cache --report-unused-disable-directives . && prettier --check .", "check-git-hooks": "cd .. && node .secret-scan/secret-scan.js -- --check-git-hooks", - "prepare": "cd .. && husky install .husky" + "prepare": "if [ -z \"$GOOGLE_FUNCTION_TARGET\" ]; then cd .. && husky install .husky; fi" }, "keywords": [], "author": "", @@ -20,8 +21,10 @@ "express": "^4.18.2", "express-validator": "^7.0.1", "firebase-admin": "^12.0.0", + "firebase-functions": "^4.7.0", "mongodb": "^6.3.0", - "mongoose": "^8.0.3" + "mongoose": "^8.0.3", + "tsc-alias": "^1.8.8" }, "devDependencies": { "@types/cors": "^2.8.17", diff --git a/backend/src/app.ts b/backend/src/app.ts index 44a06dce..6d8234e2 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -1,12 +1,12 @@ import { json } from "body-parser"; +import cors from "cors"; import express from "express"; +import { onRequest } from "firebase-functions/v2/https"; import mongoose from "mongoose"; -import studentRoutes from "../src/routes/student"; - import { mongoURI, port } from "./config"; import { errorHandler } from "./errors/handler"; -import { userRouter } from "./routes/user"; +import router from "./routes/api"; /** * Express server application class @@ -31,9 +31,12 @@ void mongoose // Middleware server.app.use(json()); -// Routes -server.app.use("/user", userRouter); -server.app.use("/student", studentRoutes); +// sets the "Access-Control-Allow-Origin" header on all responses to allow +server.app.use(cors()); + +// Prepend /api to all routes defined in /routes/api.ts +server.app.use("/api", router); + // Error Handler server.app.use(errorHandler); @@ -41,3 +44,6 @@ server.app.use(errorHandler); server.app.listen(port, () => { console.log(`> Listening on port ${port}`); }); + +// Register our express app as a Firebase Function +export const backend = onRequest({ region: "us-west1" }, server.app); diff --git a/backend/src/routes/api.ts b/backend/src/routes/api.ts new file mode 100644 index 00000000..662c7931 --- /dev/null +++ b/backend/src/routes/api.ts @@ -0,0 +1,12 @@ +import express from "express"; + +import studentRoutes from "./student"; +import { userRouter } from "./user"; + +const router = express.Router(); + +// Register routers +router.use("/user", userRouter); +router.use("/student", studentRoutes); + +export default router; diff --git a/backend/tsconfig.json b/backend/tsconfig.json index b1b1546d..36598b2d 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -55,7 +55,7 @@ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ diff --git a/firebase.json b/firebase.json index 625e10b8..bb3aa956 100644 --- a/firebase.json +++ b/firebase.json @@ -1,10 +1,49 @@ { + "functions": [ + { + "runtime": "nodejs18", + "source": "backend", + "codebase": "default", + "ignore": [ + ".git", + "firebase-debug.log", + "firebase-debug.*.log", + "**/.*", + "**/node_modules/**" + ] + } + ], "hosting": { "public": "frontend/out", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" + ], + "rewrites": [ + { + "source": "/api/**", + "function": { + "functionId": "backend", + "pinTag": true + } + }, + { + "source": "**", + "destination": "/index.html" + } ] + }, + "emulators": { + "functions": { + "port": 5001 + }, + "hosting": { + "port": 3000 + }, + "ui": { + "enabled": true + }, + "singleProjectMode": true } } From 042b67e3f060aeb8b99ab5809df13175eb5298f2 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:05:20 -0800 Subject: [PATCH 12/20] add npm ci to backend build --- .github/workflows/build-and-deploy.yml | 1 - backend/package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 1b78f52f..54182f9d 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -32,7 +32,6 @@ jobs: touch .env echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env echo SERVICE_ACCOUNT_KEY=${{ secrets.SERVICE_ACCOUNT_KEY }} >> .env - echo FRONTEND_ORIGIN=${{ vars.FRONTEND_ORIGIN }} >> .env - name: Build Frontend run: cd frontend && npm ci && npm run build - name: Build Backend diff --git a/backend/package.json b/backend/package.json index f4c73b9b..646d287f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,7 @@ "main": "dist/app.js", "scripts": { "dev": "npx ts-node-dev src/app.ts", - "build": "tsc && tsc-alias", + "build": "npm ci && tsc && tsc-alias", "format": "npm run check-git-hooks && prettier --write .", "lint-fix": "npm run check-git-hooks && (eslint --fix --cache --report-unused-disable-directives . || true) && prettier --write .", "lint-check": "npm run check-git-hooks && eslint --cache --report-unused-disable-directives . && prettier --check .", From bf300388c5acdc5e39a0d3b953d99950967030ce Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:20:05 -0800 Subject: [PATCH 13/20] delete bad casing file --- backend/src/models/User.ts | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 backend/src/models/User.ts diff --git a/backend/src/models/User.ts b/backend/src/models/User.ts deleted file mode 100644 index 4c7a7cf1..00000000 --- a/backend/src/models/User.ts +++ /dev/null @@ -1,18 +0,0 @@ -import mongoose, { InferSchemaType } from "mongoose"; - -// export type UserDocument = { -// name: string; -// accountType: "admin" | "team"; // NOTE Also stored on Firebase using Custom Claims -// approvalStatus: boolean; -// }; - -const userSchema = new mongoose.Schema({ - _id: { type: String, required: true }, // Set _id to firebaseUid; Linkage between firebase account and user document on MongoDb - name: { type: String, required: true }, - accountType: { type: String, enum: ["admin", "team"], required: true }, - approvalStatus: { type: Boolean, default: false }, // default false -}); - -type User = InferSchemaType; - -export default mongoose.model("User", userSchema); From 1788c9a111a535a4b84efb6ef41aeaf35105baf5 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:20:24 -0800 Subject: [PATCH 14/20] put back bad casing file --- backend/src/models/user.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 backend/src/models/user.ts diff --git a/backend/src/models/user.ts b/backend/src/models/user.ts new file mode 100644 index 00000000..4c7a7cf1 --- /dev/null +++ b/backend/src/models/user.ts @@ -0,0 +1,18 @@ +import mongoose, { InferSchemaType } from "mongoose"; + +// export type UserDocument = { +// name: string; +// accountType: "admin" | "team"; // NOTE Also stored on Firebase using Custom Claims +// approvalStatus: boolean; +// }; + +const userSchema = new mongoose.Schema({ + _id: { type: String, required: true }, // Set _id to firebaseUid; Linkage between firebase account and user document on MongoDb + name: { type: String, required: true }, + accountType: { type: String, enum: ["admin", "team"], required: true }, + approvalStatus: { type: Boolean, default: false }, // default false +}); + +type User = InferSchemaType; + +export default mongoose.model("User", userSchema); From aac44189f6ea062d49ada0daa7cde7df769ce61b Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:24:06 -0800 Subject: [PATCH 15/20] remove .firebase --- .firebase/hosting.ZnJvbnRlbmQvb3V0.cache | 29 ------------------------ 1 file changed, 29 deletions(-) delete mode 100644 .firebase/hosting.ZnJvbnRlbmQvb3V0.cache diff --git a/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache b/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache deleted file mode 100644 index 4aa62654..00000000 --- a/.firebase/hosting.ZnJvbnRlbmQvb3V0.cache +++ /dev/null @@ -1,29 +0,0 @@ -404.html,1707342729450,1d5d2cf8f79692cf0d5c2931356f4443ae1c0e784894979a2c92e8a712c5b5cd -index.html,1707342729447,d336204a9e548736cf813f5bb2a1c5a50cfaec42da3882f742f4a9274c49910e -next.svg,1707342729341,7b16665552cb47db34db342505d6d340caaf5813ca2cba1df3536ed67ea33f64 -notifications.html,1707342729449,d74f3f879681cb434f9a63453d21d34d4dd71531850353f5f61b69423b0f8bef -profile.html,1707342729449,4a7413e183ac2087061d7134a04f1c2a95f9112fa50b89a340b71acf5cb7cf58 -programs.html,1707342729452,0ad85ff90a9444594199ad9cb8758cd64ce5675bebe12c4af8ae717fed2ff7fe -vercel.svg,1707342729341,ddb9254655f2b7733e1193fb66cb4beb95c29ad752d7adbc1765026e124c88c5 -_next/static/FIIdxkpNmFNQdl9X9GIkT/_buildManifest.js,1707342729293,8906057e4b8aa41a4915e593ca3e0edbcfa9d3d0fd5adce0c2553072b1c3bb29 -_next/static/FIIdxkpNmFNQdl9X9GIkT/_ssgManifest.js,1707342729293,5c126729f9831113842c425975615db312fa26d39f3a9e1baa47d4ad65ac2f90 -_next/static/chunks/726-f707db82ab9098d4.js,1707342729293,0b338021b9f5301fc1a8fc475db5aae677bad5f5b7233b0f9d145ba98d48ecf4 -_next/static/chunks/framework-5429a50ba5373c56.js,1707342729293,cc7c6067a86256348371aeb89094b5e79dde940922de6558a4106fe13e8aab63 -_next/static/chunks/main-18a986b8471251f8.js,1707342729293,556690653af7cdd517cd439de6ddf6713bc9ecbcee390e333950c1f708a1adb7 -_next/static/chunks/polyfills-c67a75d1b6f99dc8.js,1707342729293,9f22ebbc1e5746bc08aa476baa8169d3ac2c27814dba6bf675b749113ac4943e -_next/static/chunks/webpack-5146130448d8adf7.js,1707342729293,76f9a07c08ba535d4656252a7ed86d7ac63a7a28415ffebe6b49c1d935afeb58 -_next/static/chunks/pages/_app-cbe5045bb6357d05.js,1707342729305,f525ac2d60ba758ddb3032b4939f5f7706ca1ae819c53b4f02879e6a2547caa0 -_next/static/chunks/pages/_error-b6491f42fb2263bb.js,1707342729305,4066094c111445f36ac1bdecf026e6a3d1db0ea93016d2c97860cf809ebc18de -_next/static/chunks/pages/index-6b9327b688bd07bd.js,1707342729305,d211d519134ade4ad01e35ec3ae1bf9934db33ed0affe35b600fdd8dce813415 -_next/static/chunks/pages/notifications-663870f95aedf130.js,1707342729305,2a071857ce2428e2d153b0ae928d1b263795a33b83ba14d523cf9f0049124366 -_next/static/chunks/pages/profile-c79e19b2230e2a09.js,1707342729306,eab412cd5f8547b81320f3dbf1a4d3da730213101c0d79bc04ba96a8f06b0119 -_next/static/chunks/pages/programs-8f2c72a07bfd7dd0.js,1707342729306,fad24f7810b4a49f9e26cfa1d0f2e9a22706262bd91527fb55b2113396df3dfa -_next/static/css/6fbe838a02cbc165.css,1707342729293,32b6ded88b74a1374d76738f67757c42cdbad33bfe9b5fcf4750176a74bebbdf -_next/static/css/7a0c8f7af9ca41c1.css,1707342729293,bf0d39db174412348b49c468d8b9c15441aa9d3511b2f5aeee7367e870785b41 -_next/static/media/591327bf3b62a611-s.woff2,1707342729293,945e04767753c910a548dca3cd5165d6d9f8d1b44c4b9a6272733f8d2cb39ddd -_next/static/media/87c72f23c47212b9-s.woff2,1707342729293,2ec4f426325ae4503262191c02f22fa491f63e233f3702be3847e05da80d367e -_next/static/media/916d3686010a8de2-s.p.woff2,1707342729293,3bf0222e823f7658ca78d05a204c5a021659b9a5afa16978b326c5b3608f228b -_next/static/media/916d3686010a8de2-s.woff2,1707342729293,3bf0222e823f7658ca78d05a204c5a021659b9a5afa16978b326c5b3608f228b -_next/static/media/Alternate Gothic No3 D Regular.df419e0a.otf,1707342729293,9164495ebf85803d6a6472eaf3f571364c1fcab3f36bc5eb8b7747019a2ba332 -sidebar/logo.png,1707342729347,45b9b90921e3d04a7ed27fc17ddf9d0cb74809836a36017ba9e70eab48faefd6 -sidebar/nav_menu.svg,1707342729347,40f2ca8d662887e01cb835ee9bf0a7766f41d196d843f342f0d40f79d42b8f57 From a43400acbef5ee62eccdfd95d0fe987b5fc45849 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:25:02 -0800 Subject: [PATCH 16/20] update gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c6bba591..e5ef1cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,6 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +# Firebase +.firebase From a5a9121d26e6ce2341a74eb777e3b27b5045bb20 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:22:19 -0800 Subject: [PATCH 17/20] update build and deploy yaml --- .github/workflows/build-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 54182f9d..78995ad3 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -42,7 +42,7 @@ jobs: uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: "${{ secrets.GITHUB_TOKEN }}" - firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" + firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PIA_DEV_60CEA }}" projectId: ${{ inputs.firebaseProjectId }} channelId: ${{ inputs.firebaseHostingChannelId }} env: From a4958b1140a26fc7d651a3fd06418bdab2a1cb6c Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:22:15 -0800 Subject: [PATCH 18/20] update build script --- .github/workflows/build-and-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 78995ad3..03ce161f 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -32,6 +32,7 @@ jobs: touch .env echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env echo SERVICE_ACCOUNT_KEY=${{ secrets.SERVICE_ACCOUNT_KEY }} >> .env + echo APP_PORT=${{ secrets.APP_PORT }} >> .env - name: Build Frontend run: cd frontend && npm ci && npm run build - name: Build Backend From cfdcf21cae599356e24c3f1ba9708ede963205a3 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:39:46 -0800 Subject: [PATCH 19/20] small refactor --- backend/src/config.ts | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/backend/src/config.ts b/backend/src/config.ts index b489c927..75968e4d 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -5,34 +5,19 @@ import { InternalError } from "./errors"; //load the env variables from .env file dotenv.config({ path: ".env" }); -let portV = ""; -let mongoV = ""; -let serviceAccountKeyV = ""; - -if (!process.env.APP_PORT) { - throw InternalError.NO_APP_PORT; -} else { - portV = process.env.APP_PORT; -} - -if (!process.env.MONGO_URI) { - throw InternalError.NO_MONGO_URI; -} else { - mongoV = process.env.MONGO_URI; -} - -if (!process.env.SERVICE_ACCOUNT_KEY) { - throw InternalError.NO_SERVICE_ACCOUNT_KEY; -} else { - serviceAccountKeyV = process.env.SERVICE_ACCOUNT_KEY; +function throwIfUndefined(envVar: string | undefined, error: InternalError) { + if (envVar === undefined) { + throw error; + } + return envVar; } -/** - * Have to do this workaround since lint doesn't let - * us export vars - */ -const port = portV; -const mongoURI = mongoV; -const serviceAccountKey = serviceAccountKeyV; +// Check if the required env variables are defined +const port = throwIfUndefined(process.env.APP_PORT, InternalError.NO_APP_PORT); +const mongoURI = throwIfUndefined(process.env.MONGO_URI, InternalError.NO_MONGO_URI); +const serviceAccountKey = throwIfUndefined( + process.env.SERVICE_ACCOUNT_KEY, + InternalError.NO_SERVICE_ACCOUNT_KEY, +); export { port, mongoURI, serviceAccountKey }; From 2b6d97a2fcaf194c516c0950c4d679ad7de5d930 Mon Sep 17 00:00:00 2001 From: parth4apple <72187062+parth4apple@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:46:10 -0800 Subject: [PATCH 20/20] update refactor --- backend/src/config.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/config.ts b/backend/src/config.ts index 75968e4d..7be6fc9b 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -6,9 +6,7 @@ import { InternalError } from "./errors"; dotenv.config({ path: ".env" }); function throwIfUndefined(envVar: string | undefined, error: InternalError) { - if (envVar === undefined) { - throw error; - } + if (!envVar) throw error; return envVar; }