diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e9881d7..33053d5 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,37 +1,40 @@ name: Build and Test on: - push: - branches: ["main"] - pull_request: - branches: ["main"] + push: + branches: ['main'] + pull_request: + branches: ['main'] jobs: - test: - runs-on: ubuntu-latest + test: + runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18] + strategy: + matrix: + node-version: [18] - steps: - - name: Checkout code - uses: actions/checkout@v3 + steps: + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: "npm" + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' - - name: Install dependencies - run: npm ci + - name: Install dependencies + run: npm ci - - name: Build - run: npm run build + - name: Set up environment variables + run: echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> $GITHUB_ENV - - name: List build artifacts - run: ls dist + - name: Build + run: npm run build - - name: Run tests - run: npm test + - name: List build artifacts + run: ls dist + + - name: Run tests + run: npm test diff --git a/src/startup/db.ts b/src/startup/db.ts index 3203051..efc3a22 100644 --- a/src/startup/db.ts +++ b/src/startup/db.ts @@ -2,7 +2,17 @@ import mongoose from 'mongoose'; const connectToDatabase = async () => { try { - await mongoose.connect(process.env.db); + const mongoURI = process.env.MONGODB_URI; + + if (!mongoURI) { + throw new Error( + 'MongoDB connection string not found in environment variables.' + ); + } + + await mongoose.connect(mongoURI); + + console.log('Connected to MongoDB'); } catch (error) { console.error('Error connecting to MongoDB:', error.message); throw error;