App crashed on Heroku server but works on local machine

System Information
  • Strapi Version: 3.2.5
  • Operating System: windows
  • Database: postgress
  • Node Version: 12
  • NPM Version: 6
  • Yarn Version:

The App is working on local machine and heroku is showing success build pass but when I try to access admin panel it says hairsalon.herokuapp.com/:1 GET https://hairsalon.herokuapp.com/ 503 (Service Unavailable) favicon.ico:1 GET https://hairsalon.herokuapp.com/favicon.ico 503 (Service Unavailable)

From the past two days I’m trying to solve app crashed H10 503 internal server but can’t find way. I have updated strapi app to 3.2.5

I didn’t get any reply from previous post that’s why I’m posting again
Please address this issue, it’s hobby level project

Seems similar to what I had https://forum.strapi.io/t/error-no-pg-hba-conf-entry-for-host-ssl-off/3409

strapi is very new in the market and we can expect such errors. project is hobby level project for portfolio showcase. Is your strapi running for real client on production?

#solved

thanks to Antoine

thanks it’s working again

I just added self assigned ssl code from strapi docs and it works

follow below steps

add below code in database.js file

 ssl: {
          rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
        },
      },
      options: {
        ssl: env.bool('DATABASE_SSL', false),
      },````

## complete database.js file looks like 

``` // localhost

// module.exports = ({ env }) => ({
//   defaultConnection: 'default',
//   connections: {
//     default: {
//       connector: 'bookshelf',
//       settings: {
//         client: 'sqlite',
//         filename: env('DATABASE_FILENAME', '.tmp/data.db'),
//       },
//       options: {
//         useNullAsDefault: true,
//       },
//     },
//   },
// });

// production

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: env('DATABASE_HOST', '127.0.0.1'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        username: env('DATABASE_USERNAME', ''),
        password: env('DATABASE_PASSWORD', ''), 
        //add this line
        ssl: {
          rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
        },     
      },
      // add this line
      options: {
        ssl: env.bool('DATABASE_SSL', false),
      },
    },
  },
});


And my server.js file looks like

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    },
  },
});```

yes, mine is running in production for a couple of months, and this has been the only real downtime I had. But Heroku is to blame too, they changed stuff

yes you’re right. I think they changed because of recent news from chrome about ssl certificate

Hi, I am also facing the same issue and haven’t solved it yet.

My server.js file for the dev environment looks like this:

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    },
  },
});

And for the production environment, it looks like:

module.exports = ({ env }) => ({
  url: env("HEROKU_URL"),
});

Do I need to change the server.js for the production environment?

App crashed on Heroku like H10 error occur due to several reason and in my case it was related to certificated due to heroku stack updated

In my strapi version": “0.1.0” I have one server.js for both prod and dev mode but in your case you have separate mode, may be that’s new updated strapi version

you said you’re facing same problem so try adding ssl in database.js file

// production

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: env('DATABASE_HOST', '127.0.0.1'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        username: env('DATABASE_USERNAME', ''),
        password: env('DATABASE_PASSWORD', ''), 
        //add this line
        ssl: {
          rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
        },     
      },
      // add this line
      options: {
        ssl: env.bool('DATABASE_SSL', false),
      },
    },
  },
});

Hi Ali, thank you for the help.

Yes, you are right, there can be multiple reasons for the Heroku app being crashed.

And I found that my app was being crashed NOT because of SSL.

My database.js and sever.js file were configured correctly.

The mistake I was making that I added some new collections types and also made some fields “required”.

When I pushed these changes to the Heroku, the existing Heroku Postgres database did not have values for these required fields. Postgres was returning the NULL values for the new fields. So, this was creating the issue.

Another important thing is that always have Heroku CLI installed. I was just relying on the Heroku dashboard logs and it doesn’t provide the detailed logs.

When I installed the Heroku CLI and run the command for logs, I found this error log:

2021-07-07T18:01:06.214885+00:00 app[web.1]: [2021-07-07T18:01:06.214Z] error error: alter table "writers" add column "slug" varchar(255) not null, add column "title" varchar(255) not null, add column "description" text not null - column "slug" of relation "writers" contains null values

How I was able to solve this issue?

I made those fields NOT required in the local development and then pushed the changes. After that, I added values for those fields on the Heroku instance of my app. And then I mark the fields as “required” in the local development. And then pushed changes again to Heroku.

I am not sure whether this correct way of solving the problem or just a workaround BUT this is what worked for me.

Thanks.