Image Search Abstraction Layer crash in Heroku

Image Search Abstraction Layer crash in Heroku
0.0 0

#1

Hello guys,
I just finished the Image Search Abstraction Layer exercise. It’s running fine on local but crashes in Heroku. I checked the code several times even posts here and in other forums, but can’t make it work, it’s turning kind of frustrating now.
The Heroku log is this:

2017-06-02T15:54:50.697678+00:00 app[web.1]:     at Url.parse (url.js:269:19)

2017-06-02T15:54:50.697679+00:00 app[web.1]:     at Object.urlParse [as parse] (url.js:75:5)

2017-06-02T15:54:50.697680+00:00 app[web.1]:     at module.exports (/app/node_modules/mongodb/lib/url_parser.js:15:23)

2017-06-02T15:54:50.697681+00:00 app[web.1]:     at connect (/app/node_modules/mongodb/lib/mongo_client.js:442:16)

2017-06-02T15:54:50.697681+00:00 app[web.1]:     at Function.MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:241:3)

2017-06-02T15:54:50.697682+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:75:13)

2017-06-02T15:54:50.697683+00:00 app[web.1]:     at Module._compile (module.js:571:32)

2017-06-02T15:54:50.697683+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:580:10)

2017-06-02T15:54:50.697684+00:00 app[web.1]:     at Module.load (module.js:488:32)

2017-06-02T15:54:51.050532+00:00 heroku[web.1]: State changed from starting to crashed

2017-06-02T16:02:47.320896+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=image-search-edo.herokuapp.com request_id=b7eeef4c-e9d8-4d0e-aaf0-f6c608a5b1d1 fwd="90.74.187.247" dyno= connect= service= status=503 bytes= protocol=https

Thanks for your time, hope you can help me with this problem.


#2

It’s not clear what the problem is without the code, It’s better if you place the link to your codes here.
There should probably be something wrong with your config.json file. maybe you have missed a dependency. But its hard to tell without seeing the code.

You might want to check what happens if you copy your project tree without the node-modules folder to another folder then running npm install and then see if it’s working or not.


#3

Hello tuxitop, thanks for your answer. Sorry, I forgot to put my repository files, here they are:
GitHub

So you propose to uninstall all the node modules and run npm install in the Procfile?

Thanks again.


#4

I think the problem is how you referencing the public folder, the server can’t reach the folder by the path you’re using, which is now:

app.use(express.static(’./public’));

try changing this line to something like:

app.use(express.static(__dirname + “/public”));

https://expressjs.com/en/starter/static-files.html

excerpt:
However, the path that you provide to the express.static function is relative to the directory from where you launch your node process. If you run the express app from another directory, it’s safer to use the absolute path of the directory that you want to serve:

This would also potentially explain why it works locally but not on Heroku.


#5

Hello s_coder,
I tried that solution before, but still not working, anyway, you are right, the path should be absolute so I’m leaving your suggestion with a little change:

app.use('/', express.static(path.join(__dirname, 'public')));

and add the path require for that:
var path = require('path');

Still not working in Heroku, but the logs changed:

2017-06-03T07:54:11.481475+00:00 heroku[web.1]: State changed from crashed to starting
2017-06-03T07:54:13.077920+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-06-03T07:54:15.357831+00:00 heroku[web.1]: Process exited with status 1
2017-06-03T07:54:15.369954+00:00 heroku[web.1]: State changed from starting to crashed
2017-06-03T07:54:15.265876+00:00 app[web.1]: url.js:269
2017-06-03T07:54:15.265891+00:00 app[web.1]:       this.auth = decodeURIComponent(rest.slice(0, atSign));
2017-06-03T07:54:15.265892+00:00 app[web.1]:                   ^
2017-06-03T07:54:15.265892+00:00 app[web.1]: 
2017-06-03T07:54:15.265893+00:00 app[web.1]: URIError: URI malformed
2017-06-03T07:54:15.265894+00:00 app[web.1]:     at decodeURIComponent (<anonymous>)
2017-06-03T07:54:15.265895+00:00 app[web.1]:     at Url.parse (url.js:269:19)
2017-06-03T07:54:15.265895+00:00 app[web.1]:     at Object.urlParse [as parse] (url.js:75:5)
2017-06-03T07:54:15.265896+00:00 app[web.1]:     at module.exports (/app/node_modules/mongodb/lib/url_parser.js:15:23)
2017-06-03T07:54:15.265897+00:00 app[web.1]:     at connect (/app/node_modules/mongodb/lib/mongo_client.js:442:16)
2017-06-03T07:54:15.265898+00:00 app[web.1]:     at Function.MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:241:3)
2017-06-03T07:54:15.265898+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:77:13)
2017-06-03T07:54:15.265899+00:00 app[web.1]:     at Module._compile (module.js:571:32)
2017-06-03T07:54:15.265900+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:580:10)
2017-06-03T07:54:15.265900+00:00 app[web.1]:     at Module.load (module.js:488:32)
2017-06-03T07:54:36.407726+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=image-search-edo.herokuapp.com request_id=fdc93ed8-e888-4efa-9e45-263e42c1b464 fwd="90.74.187.247" dyno= connect= service= status=503 bytes= protocol=https

Any ideas? Thank you s_coder.


#6

#7

Thanks for the help, finally I found the error in case someone else have the same problem. My mongodb password contains a porcentage sign (%) and this causes the decodeURIComponent problem, it seems that there is a problem supporting #@% signs, so you have to encoded them or just change your db password avoiding those signs.
Hope it helps.
Thank you guys.