Knex Postgres Heroku - 错误:无法获取连接

时间:2017-08-21 17:38:53

标签: postgresql heroku knex.js

我知道这里的帖子和类似问题(Knex Migration Postgres Heroku - Error: Unable to Acquire Connection)我不确定我的.env中缺少什么我只是在那里基本上有以下一行:HOST = { {3}}

我的knexfile:

const environment = process.env.NODE_ENV || 'development';
const knexConfig = require('./knexfile')[environment];
const knex = require('knex')(knexConfig);

module.exports = knex;

Knex文件:

const express= require('express');
const PORT = process.env.PORT || 3000;
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors');
const usersRoute = require('./routes/users');

if (process.env.NODE_ENV !== 'production') {
  require('dotenv').config();
}

const allowCrossDomain = function (req, res, next) {
  res.header('Access-Control-Allow-Credentials', true);
  res.header('Access-Control-Allow-Origin', req.headers.origin);
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
  if (req.method == 'OPTIONS') {
    res.send(200);
  } else {
    next();
  }
};

app.use(allowCrossDomain);

app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(express.static(path.join(__dirname, 'build')));

app.use('/api', usersRoute);

app.listen(PORT, () => {
  console.log(`Express server listening on port ${PORT}`);
});

module.exports = app;

app.js文件:

$d ="May 23, 2017";
Echo strtotime($d) ."<br>\n";
Echo date("Y-m-d", strtotime($d));

1 个答案:

答案 0 :(得分:0)

您需要在Heroku设置中定义NODE_ENV=production环境变量,并检查DATABASE_URL变量的内容。