1

I am new in Bluemix. So far I created web app,got its code and run this app in localhost. Everything works good. The app uses AngularJs and json-server. Later on I will Node.js too. To run it I use 'json-server --watch db.json'. The json file contains various json arrays and objects. And this is my list of links.

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

My guess is that all those links should be changed to a live route instead of using localhost. In my dashboard I can see the name's app the route(theo-larissa.mybluemix.net) and it's state with is stopped. Now when I am trying to start the app,I get this message

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

Any ideas how to fix this?

Thanks in advance,

Theo.

Theo
  • 3,099
  • 12
  • 53
  • 94
  • What commands did you execute? What do you mean with "when I started the app"? – data_henrik May 29 '17 at 08:11
  • 1
    It's saying 'does not exist' 'cos it's stopped. The real Q might be why that is. I'd check your logs, probably `cf logs theo-larissa --recent`. And maybe look at the sample, see how it handles the hostname/port. https://console.ng.bluemix.net/docs/runtimes/nodejs/getting-started.html#getting-started-with-node-js-on-bluemix – amadain May 30 '17 at 08:48

2 Answers2

1

What do your console logs for theo-larissa.mybluemix.net show? One of the really common deployment mistakes is to leave the port hard-coded in your application when you deploy it to Bluemix. You can't do that; you have to allow Bluemix to specify the port your application will use. You would do that, for example, by encoding something like the following when you create the server:

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

If you wanted to make this fully automated, you could include code like the following:

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);});
  }
Bob Dill
  • 1,000
  • 5
  • 13
  • Thanks for the answer. It's all good now. Unfortunately though Bluemix doesn't support anymore MongoDB. :(. – Theo Jun 06 '17 at 15:08
  • 1
    Theo, Mongo is supported as Compose for Mongo. You can find it here: https://console.ng.bluemix.net/catalog/services/compose-for-mongodb?env_id=ibm:yp:us-south&taxonomyNavigation=services If you want a free, NoSQL db in Bluemix, you could use Cloudant, which I've successfully deployed on multiple applications. Cloudant as a service is available here: https://console.ng.bluemix.net/catalog/services/cloudant-nosql-db?env_id=ibm:yp:us-south&taxonomyNavigation=services – Bob Dill Jun 06 '17 at 15:30
-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);});
  }
AlessioX
  • 3,167
  • 6
  • 24
  • 40
  • 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);}); } share edit – Gaurya Chaudari Mar 04 '18 at 06:05
  • Welcome to Stack Overflow! While this code snippet may be the solution, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – xskxzr Mar 04 '18 at 06:26