Pg Promise timeout while using express generator format, but works fine with basic express sever

耗尽温柔 提交于 2020-12-16 07:03:20

问题


Pg-promise is Not returning anything for 60s and gets timed out while running server setup with express-generator. There are no error messages.

All the routes without db.any or similar query, works fine. The routes with db.* times out.

But, the same connection/route/query works perfectly with a simple express app.

I am running this from AWS EC2.

Here is the test sample express that worked fine. Same route in routes/index.js does not work - gets timed out.

const express = require('express');
const app = express();

const options = {
  query: function (e) {
    console.log(e.query);
  },
};

const pgp = require('pg-promise')(options);
const connection = 'postgres://user:pwd@endpoint:5432/db';
const db = pgp(connection);

app.get('/test', (req, res) => {
  db.any('select id from users')
    .then(data => {
      res.json({
        data,
      });
    }).catch(err => {
      res.json({
        err,
      });
    });
});

app.listen(4000, () => {
  console.log('db app listening on port 4000!');
});

module.exports = app;

Not sure what I am missing? What could be the issue!

来源:https://stackoverflow.com/questions/65152018/pg-promise-timeout-while-using-express-generator-format-but-works-fine-with-bas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!