2016-10-18 34 views
1

データベースに接続する必要のある簡単なWebアプリケーションがあります。私はpublicというユーザーを作成しましたが、これはデータベースからのみ選択できます。NodeJS + MySQLはlocalhostから接続しますが、herokuは接続しません。

すべてがローカルホストから完全に正常に動作します。私はHerokuの上でアプリを展開し、そしてそれは私に次のエラーを与える:

2016-10-18T00:17:59.282323+00:00 app[web.1]: Couldn't connect :( Error: connect ETIMEDOUT 2016-10-18T00:17:59.282562+00:00 app[web.1]: Something went wrong... Error: connect ETIMEDOUT

app.get("/", function(request, response){ 
    response.render("index"); 
}); 

// request for quotes is received 
app.get("/get", function(req, res){ 

    // open a connection to the database 
    var connection = mysql.createConnection({ 
     connectionLimit: 100, 
     host: "my-test-database.c3j6vph7cyv2.us-west-2.rds.amazonaws.com", 
     user: "public", 
     password:"helloworld", 
     database:"quotes" 
    }); 

    // connect to the database 
    connection.connect(function(error){ 
     if(error){ 
      console.log("Couldn't connect :( " + error); 
     } else { 
      console.log("Connected successfully~!"); 
     }  
    }); 

    // retrieve quotes from database 
    connection.query("SELECT * FROM Quotes", function(error, rows, fields){ 
     if (error) { 
      console.log("Something went wrong... " + error); 
      res.end(); 
     } else { 
      res.jsonp({"quotes": rows}); 
     } 
    }); 

    connection.end(); 
}); 

答えて

4

あなたのコード内のURLから(RDSにアクセスするには、Herokuののdynosを承認する必要があるようだ、私はあなたがそれを使用していると仮定します)。手順についてはthis linkをご確認ください

+0

ありがとうございます!それは働いた –

関連する問題