2017-05-28 40 views
1

我是Bluemix中的新成員。到目前爲止,我創建了Web應用程序,獲得了它的代碼並在localhost中運行這個應用程序一切正常。該應用使用AngularJs和json-server。稍後我也會Node.js。要運行它,我使用'json-server --watch db.json'。 json文件包含各種json數組和對象。這是我的鏈接列表。404未找到:請求的路線('theo-larissa.mybluemix.net')不存在

http://localhost:3000/news 
http://localhost:3000/events 
http://localhost:3000/city 
http://localhost:3000/administration 
http://localhost:3000/deputy_mayors 
http://localhost:3000/alcazar_park 
http://localhost:3000/feedback 

我的猜測是,所有這些鏈接應改爲實時路線,而不是使用本地主機。在我的儀表板中,我可以看到路由名稱的應用(theo-larissa.mybluemix.net),並且它的狀態已停止。現在,當我試圖啓動應用程序,我得到這個消息

404 Not Found: Requested route ('theo-larissa.mybluemix.net') does not exist.

任何想法如何解決這一問題?

由於提前,

西奧。

+0

你執行了哪些命令? 「當我開始使用應用程序」時,你的意思是什麼? –

+1

這是說'不存在'因爲它停止了。真正的Q可能是這是爲什麼。我會檢查你的日誌,可能是'cf logs theo-larissa --recent'。也許看看示例,看看它如何處理主機名/端口。 https://console.ng.bluemix.net/docs/runtimes/nodejs/getting-started.html#getting-started-with-node-js-on-bluemix – amadain

回答

1

您的控制檯日誌foro-larissa.mybluemix.net顯示什麼?其中一個非常常見的部署錯誤是在將應用程序部署到Bluemix時將端口硬編碼到您的應用程序中。你不能那樣做;您必須允許Bluemix指定您的應用程序將使用的端口。當您創建的服務器,你會做到這一點,例如,通過編碼類似如下:

var server = app.listen(app.get('port'), function() 
    {console.log('Listening on port %d', server.address().port);}); 

如果你想使這個完全自動化的,可以包括像下面的代碼:

app.set('port', appEnv.port); 
app.set('appName', 'theo-larissa'); 

if (cfenv.getAppEnv().isLocal == true) 
    {http.createServer(app).listen(app.get('port'), 
    function(req, res) {console.log(app.get('appName')+' is listening locally on port: ' + app.get('port'));}); 
    } 
    else 
    { 
    var server = app.listen(app.get('port'), function() {console.log('Listening on port %d', server.address().port);}); 
    } 
+0

謝謝你的答案。現在都很好。不幸的是,儘管Bluemix不再支持MongoDB。 :(。 – Theo

+1

Theo,Mongo支持作爲Mongo的Compose。您可以在這裏找到它: https://console.ng.bluemix.net/catalog/services/compose-for-mongodb?env_id=ibm:yp:us -south&taxonomyNavigation = services如果您希望在Bluemix中擁有一個免費的NoSQL數據庫,則可以使用Cloudant,我已經成功部署到多個應用程序中。Cloudant作爲服務可在此處找到:https://console.ng.bluemix.net/目錄/ services/cloudant-nosql-db?env_id = ibm:yp:us-south&taxonomyNavigation = services –

-1
app.set('port', appEnv.port); 
app.set('appName', 'theo-larissa'); 

if (cfenv.getAppEnv().isLocal == true) 
    {http.createServer(app).listen(app.get('port'), 
    function(req, res) {console.log(app.get('appName')+' is listening locally on port: ' + app.get('port'));}); 
    } 
    else 
    { 
    var server = app.listen(app.get('port'), function() {console.log('Listening on port %d', server.address().port);}); 
    } 
+0

app.set('port',appEnv.port); app.set('appName','theo-larissa') ; if(cfenv.getAppEnv()。isLocal == true) {http.createServer(app).listen(app.get('port'), function(req,res){console.log(app。 get('appName')+'正在本地監聽端口:'+ app.get('port'));});()),函數(){console.log('監聽端口%d',server.address().port);}){var_server_login(app.get('port'), ; } 分享編輯 –

+0

歡迎來到Stack Overflow!儘管此代碼片段可能是解決方案,但[包括解釋](// meta.stackexchange.com/questions/114762/explaining-entirely-基於代碼的答案)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – xskxzr

相關問題