0

I'm getting an error trying to deploy my heroku application.

Here is the current error I am getting.

2021-02-21T04:36:31.869983+00:00 app[web.1]: Failed to prune sessions: no pg_hba.conf entry for host "xxx", user "xxx", database "xxx", SSL off
2021-02-21T04:36:32.338996+00:00 heroku[web.1]: State changed from starting to up
2021-02-21T04:38:58.729590+00:00 app[web.1]: at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:278:15)
2021-02-21T04:38:58.729590+00:00 app[web.1]: at Parser.handlePacket (/app/node_modules/pg-protocol/dist/parser.js:126:29)
2021-02-21T04:38:58.729591+00:00 app[web.1]: at Parser.parse (/app/node_modules/pg-protocol/dist/parser.js:39:38)
2021-02-21T04:38:58.729591+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/pg-protocol/dist/index.js:10:42)
2021-02-21T04:38:58.729592+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2021-02-21T04:38:58.729592+00:00 app[web.1]: at addChunk (_stream_readable.js:302:12)
2021-02-21T04:38:58.729593+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:278:9)
2021-02-21T04:38:58.729593+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:217:10)
2021-02-21T04:38:58.729594+00:00 app[web.1]: at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

This is my current code for my server.js

const keys = require("./config/keys");

const express = require(`express`);
const passport = require(`passport`);
const session = require(`express-session`);
const postGresqlStore = require("connect-pg-simple")(session);
const usersRouter = require(`./src/routes/users`);
const flash = require(`connect-flash`);

const initializePassport = require("./passportConfig");
initializePassport(passport);

const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
  session({
    store: new postGresqlStore({
      conString:
        process.env.NODE_ENV === `production`
          ? process.env.DATABASE_URL
          : `postgres://${keys.DB_USER}:${keys.DB_PASSWORD}@${keys.DB_HOST}:${keys.DB_PORT}/${keys.DB_DATABASE}`,
    }),
    secret: keys.SESSION_SECRET,
    resave: false,
    saveUninitialized: false,
    cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 },
  })
);
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(usersRouter);

const path = require("path");
if (process.env.NODE_ENV === "production") {
  // Serve any static files
  app.use(express.static("client/build"));
  // Handle React routing, return all requests to React app
  app.get("*", function (req, res) {
    res.sendFile(path.join(__dirname, "client", "build", "index.html"));
  });
}

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
  console.log(`Alright you got it! running on ${PORT}`);
});

This is my db.config.js

const keys = require(`./config/keys`);

const { Pool } = require("pg");

const isProduction = process.env.NODE_ENV === `production`;

const connectionString = `postgres://${keys.DB_USER}:${keys.DB_PASSWORD}@${keys.DB_HOST}:${keys.DB_PORT}/${keys.DB_DATABASE}`;

const pool = new Pool({
  connectionString: isProduction ? keys.DATABASE_URL : connectionString,
});

module.exports = { pool };

Does anyone have any idea whats going wrong?? Am I not putting the correct credentials in connect-pg-simple?

Thanks for the help!

rayDoggy1
  • 23
  • 1
  • 3

0 Answers0