2013-02-05 39 views
0

我一直在開發我的第一個Node.js應用程式(實際上,把一些舊代碼以節點爲樂趣和實踐),並正與它託管在Heroku上播放。的Heroku的Node.js應用程序無法啓動

我已經能夠得到應用,因​​爲它主張用工頭運行順順當當本地,但每當我部署應用的Heroku它開始,但未能滿足查詢。我已經做了一些研究,找不到任何具體的東西,但它在我看來像幾個模塊沒有被Heroku正確安裝

MySQL數據庫託管在亞馬遜RDS,和我已經跟蹤和複覈的步驟,訪問權限和安全例外和似乎沒有成爲一個問題。

我使用以下模塊,在我的package.json定義:

{ 
"name": "AppName", 
"version": "0.0.1", 
"dependencies": { 
    "express": "2.5.x", 
    "jade": "0.28.1", 
    "stylus": "0.32.0", 
    "mysql": "2.0.0-alpha7", 
    "string": "1.2.*", 
    "sanitizer": "0.0.*", 
    "validator": "0.4.8" 
}, 
"engines": { 
"node": "0.8.*", 
"npm": "1.*.*" 
} 
} 

在我的應用程序文件的頂部調用:

var express = require('express'); 
var crypto = require('crypto'); 
var S = require('string'); 
var mysql = require('mysql'); 
var sanitizer = require('sanitizer'); 
var check = require('validator').check, 
sanitize = require('validator').sanitize; 

該錯誤消息如下:

TypeError: Cannot call method 'query' of undefined 
at pool.getConnection.app.get.connection.query.res.render.global_title (/app/web.js:40:14) 
at callbacks (/app/node_modules/express/lib/router/index.js:272:11) 
at param (/app/node_modules/express/lib/router/index.js:246:11) 
at pass (/app/node_modules/express/lib/router/index.js:253:5) 
at Router._dispatch (/app/node_modules/express/lib/router/index.js:280:5) 
at Object.middleware [as handle] (/app/node_modules/express/lib/router/index.js:45:10) 
at next (/app/node_modules/express/node_modules/connect/lib/http.js:204:15) 
at Object.stylus (/app/node_modules/stylus/lib/middleware.js:181:7) 
at next (/app/node_modules/express/node_modules/connect/lib/http.js:204:15) 
at Object.methodOverride [as handle]  (/app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5) 

而且代碼段失敗:

pool.getConnection(function(err, connection) { 

app.get('/', function(req, res){ 

    connection.query('QUERY_HERE', function(err, rows, fields) { 
     if (err) throw console.log(err); 

     res.render('index', { 
     global_title: S(site_title).stripTags().s, 
     title: S(rows[0].title).stripTags().s, 
     bodytext: sanitize(sanitizer.sanitize(rows[0].content)).xss() 
     }); 

     connection.end(); 

    }); 
}); 
//end connection 
}); 

這是唯一的錯誤的Heroku給我在瀏覽器或日誌,它似乎並沒有有任何麻煩,構建它。

我是那種在這裏損失,所以希望有人能指出確切位置,我是一個傻瓜,讓我滾之前,我求助於接觸的Heroku!

在此先感謝。

更新:

利用帕斯卡Belloncle建議代碼變化來捕捉錯誤在日誌中產生一個應用程序錯誤在瀏覽器中,並在日誌中的以下內容:

connection.query(QUERY, function(err, row 
at Handshake.Sequence.end (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24) 
at Protocol.handleNetworkError (/app/node_modules/mysql/lib/protocol/Protocol.js:230:14) 
at Socket.EventEmitter.emit (events.js:126:20) 
at Socket._destroy.self.errorEmitted (net.js:328:14) 
TypeError: Cannot call method 'query' of undefined 
at process.startup.processNextTick.process._tickCallback (node.js:244:9) 
at Handshake.Pool.getConnection [as _callback] (/app/node_modules/mysql/lib/Pool.js:35:9) 
at Connection._handleNetworkError (/app/node_modules/mysql/lib/Connection.js:145:18) 
at /app/web.js:40:15 

似乎仍在同一點上崩潰而沒有有用的錯誤。

更新2:

錯誤信息!

2013-02-06T06:32:57+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path=/ host=trash-media.herokuapp.com fwd=31.3.253.10 dyno=web.1 queue=0ms wait=0ms connect=4ms service=21033ms status=503 bytes=0 

https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response

更新3:

從更新2的錯誤訊息,並做一些擺弄,在RDS的安全設置後,這個現在看起來它是關係到差在Heroku託管的地方(美國西部)和我的RDS數據庫(歐盟西部)之間的可用區域。我已經用Heroku支持提出了這個問題,並且我會得到一個答案來關閉這個問題,並且希望得到一個可行的解決方案或解決方法。

回答

0

我關閉這個問題,因爲這個問題現在似乎在可用性區域在AWS之間在Heroku的應用程序是(美國),並且其中RDS是(歐盟)相關的差異。

儘管根據RDS開發人員工具演練中的建議更改了區域,但Heroku仍然無法與我的RDS進行交互。

這種情況的解決方法是更改​​安全組策略的RDS數據庫允許所有連接:

0.0.0.0/0 

或數據庫移動到美國的可用性區域。

幾乎不理想。

我現在已經等了四天Heroku支持的回覆以及任何其他建議,所以如果他們回來,我會將它們添加到這個答案。

1

檢查第一行的err值。如果連接未定義,很可能是因爲您有錯誤。

另外,您應該在每個請求上獲得新的連接,然後返回到池。

app.get('/', function(req, res){ 
    pool.getConnection(function(err, connection) { 
    if (err) { 
     console.error("getConnection", err); 
    } 
    // do stuff here 
    connection.end(); // return connection to the pool 
    }); 
}); 
+0

感謝您的建議!我試過你的建議。現在,它導致瀏覽器出現平面應用程序錯誤,並在日誌中出現錯誤。我已經用它更新了這個問題。 – PenguinOfwar