2017-08-21 11 views
0

を取得することができません。私はポストの意識だと、ここで同様の質問(Knex Migration Postgres Heroku - Error: Unable to Acquire Connection)私はちょうど基本的にそこに次の行を持って私の.envに欠けているかわからないんだけど:HOST = http://localhost:3000Knex PostgresのHerokuの - エラー:接続

マイknexfile:

module.exports = { 

    development: { 
    client: 'pg', 
    connection: 'postgres://localhost/eka_dev', 
    migrations: { 
     tableName: 'knex_migrations' 
    } 
    }, 

    test: { 
    client: 'pg', 
    connection: 'postgres://localhost/eka_test', 
    migrations: { 
     tableName: 'knex_migrations' 
    } 
    }, 

    production: { 
    client: 'pg', 
    connection: process.env.DATABASE_URL, 
    migrations: { 
     tableName: 'knex_migrations' 
    } 
    } 
}; 

Knexファイル:

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

module.exports = knex; 

app.jsファイル:

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; 

答えて

0

あなたはHerokuのセットアップでNODE_ENV=production環境変数を定義し、何を確認する必要があります変数DATABASE_URLの内容です。

関連する問題