500 internal server error from Express app on Heroku using Postgres and Knex

my app works locally and I can post to all of my endpoints successfully, but after deploying to Heroku, creating a postgres addon, and running migrations -- the endpoints are no longer working.

I can still query the endpoint './' in my app.js and get back 'hello world'. So I know the app is connected.

But when I try to post to any endpoint (with my client or from postman) I only get back an unhelpful 500 internal server error message.

500 internal server error in my console

I can verify the tables have been created in the heroku database by connecting to it and running the \dt command

connected to the db on Heroku and showing created tables

Although I'm still not 100% sure that the db and postgres are associated correctly, I think they are. Maybe this will help someone verify that for me.

enter image description here

I think the problem is in my configuration and Heroku not assigning the DATABASE_URL environmental variable correctly, but everything looks correct to me.

I've tried making every small change I could find on the internet like using the url string directly instead of DATABASE_URL, and adding ssl=true in about 3 or 4 different locations.

I noticed a lot of people online use a knexfile.js instead of postgrator.js for config so maybe that's what I'll try next.

The problem could also be in the package.json. Right now I have my full DB string included there but I've tried with DATABASE_URL also.

Here is most of the code that could be relevant. Many thanks

Procfile

web: node src/server.js

config.js

module.exports = {
PORT: process.env.PORT || 8000,
NODE_ENV: process.env.NODE_ENV || 'development',
DATABASE_URL: process.env.DATBASE_URL|| 'postgresql://postgres@localhost/spiral',
TEST_DATABASE_URL: process.env.TEST_DATBASE_URL || 'postgresql://postgres@localhost/spiral_test'

}

postgrator-config.js

require('dotenv').config();

module.exports = {
  "migrationsDirectory": "migrations",
  "driver": "pg",
  "connectionString":   
  process.env.NODE_ENV === 'test'
  ? process.env.TEST_DATABASE_URL
  : process.env.DATABASE_URL,
'ssl': !!process.env.SSL,
}

package.json

{
    "name": "spiral-server",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "mocha --require test/setup.js",
        "dev": "nodemon src/server.js",
        "start": "node src/server.js",
        "migrate": "postgrator --config postgrator-config.js",
        "migrate:test": "env NODE_ENV=test npm run migrate",
        "migrate:production": "env SSL=true DATABASE_URL=$(heroku confi[![enter image description here][3]][3]g:get postgres://[my db and account info string] ?ssl=true) npm run migrate",
        "predeploy": "npm audit",
        "deploy": "git push heroku master",
        "postdeploy": "npm run migrate:production"
    },
    "keywords": [],
    "engines": {
        "node": "12.14.1"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
        "cors": "^2.8.5",
        "dotenv": "^8.2.0",
        "express": "^4.17.1",
        "helmet": "^4.1.0",
        "knex": "^0.21.5",
        "morgan": "^1.10.0",
        "pg": "^8.3.3",
        "postgrator": "^4.0.1",
        "postgrator-cli": "^3.2.0",
        "xss": "^1.0.8"
    },
    "devDependencies": {
        "chai": "^4.2.0",
        "mocha": "^8.1.1",
        "nodemon": "^2.0.4",
        "supertest": "^4.0.2"
    }
}

One of my routes -- maybe I could configure my error message better here to help me?

const projectRouter = express.Router()
const jsonParser = express.json()

projectRouter
  .route('/')
  .get((req, res, next) => {
    ProjectService.getAllProjects(
      req.app.get('db')
    )
      .then(projects => {
        res.json(projects)
      })
      .catch(next)
  })
  .post(jsonParser, (req, res, next) => {
    const { account, project } = req.body
    const newProject = { account, project }

    for (const [key, value] of Object.entries(newProject)) {
             if (value == null) {
               return res.status(400).json({
                 error: { message: `Missing '${key}' in request body` }
               })
             }
           }