简体   繁体   中英

node.js deployment on Heroku

I tried deploying a node.js test app to heroku and from what I can gather from the heroku log file it is working fine

    2017-02-09T12:25:56.034718+00:00 heroku[web.1]: Starting process with command `npm start`
    2017-02-09T12:25:58.779864+00:00 app[web.1]:
    2017-02-09T12:25:58.779890+00:00 app[web.1]: > my_app@1.0.0 start /app
    2017-02-09T12:25:58.779890+00:00 app[web.1]: > node app.js
    2017-02-09T12:25:58.779891+00:00 app[web.1]:
    2017-02-09T12:25:59.050233+00:00 app[web.1]: App listening on port 49664
    2017-02-09T12:25:59.690629+00:00 heroku[web.1]: State changed from starting to up
    2017-02-09T12:26:05.265181+00:00 heroku[router]: at=info method=GET path="/" host=my-app.herokuapp.com request_id=fbc82114-bce8-4a52-aa6b-7a097cd561ff fwd="92.40.249.7" dyno=web.1 connect=0ms service=14ms status=304 bytes=237
    2017-02-09T12:26:05.442325+00:00 heroku[router]: at=info method=GET path="/bower_components/bootstrap/dist/css/bootstrap.css" host=my-app.herokuapp.com request_id=6e619bad-5c2b-4b41-b6e1-cbbe0d7e0ee1 fwd="92.40.249.7" dyno=web.1 connect=0ms service=10ms status=404 bytes=260
    2017-02-09T12:26:05.577867+00:00 heroku[router]: at=info method=GET path="/bower_components/bootstrap/dist/css/bootstrap-theme.css" host=my-app.herokuapp.com request_id=fef14f4e-5482-4a8b-be1c-49031c174ab3 fwd="92.40.249.7" dyno=web.1 connect=0ms service=3ms status=404 bytes=266
    2017-02-09T12:26:05.730904+00:00 heroku[router]: at=info method=GET path="/bower_components/jquery/dist/jquery.js" host=my-app.herokuapp.com request_id=4efdebb4-3b34-47d4-883a-11f1dcade9ee fwd="92.40.249.7" dyno=web.1 connect=1ms service=2ms status=404 bytes=249
    2017-02-09T12:26:05.731243+00:00 heroku[router]: at=info method=GET path="/style.css" host=my-app.herokuapp.com request_id=deccbb20-285c-48f5-89e0-f97f09ce6476 fwd="92.40.249.7" dyno=web.1 connect=0ms service=2ms status=304 bytes=236
    2017-02-09T12:26:05.851411+00:00 heroku[router]: at=info method=GET path="/controllers/homeController.js" host=my-app.herokuapp.com request_id=83e6f6cd-060c-4b6b-9340-92cf0acfcc4e fwd="92.40.249.7" dyno=web.1 connect=1ms service=2ms status=304 bytes=237
    2017-02-09T12:26:05.721263+00:00 heroku[router]: at=info method=GET path="/bower_components/angular/angular.js" host=my-app.herokuapp.com request_id=2d0c81c1-d24a-476c-bff9-125014b715da fwd="92.40.249.7" dyno=web.1 connect=1ms service=2ms status=404 bytes=246
    2017-02-09T12:26:05.759107+00:00 heroku[router]: at=info method=GET path="/app.js" host=my-app.herokuapp.com request_id=763a04bf-17dd-4e3b-946d-d82f8349244a fwd="92.40.249.7" dyno=web.1 connect=1ms service=3ms status=304 bytes=236
    2017-02-09T12:26:05.718950+00:00 heroku[router]: at=info method=GET path="/bower_components/angular-route/angular-route.js" host=my-app.herokuapp.com request_id=52126a4e-f43d-468b-b649-f6159def75f3 fwd="92.40.249.7" dyno=web.1 connect=1ms service=2ms status=404 bytes=258
    2017-02-09T12:26:05.780506+00:00 heroku[router]: at=info method=GET path="/bower_components/lodash/dist/lodash.js" host=my-app.herokuapp.com request_id=1fced25e-ff4e-42b2-afa6-f402b8438d09 fwd="92.40.249.7" dyno=web.1 connect=1ms service=3ms status=404 bytes=249
    2017-02-09T12:26:05.864505+00:00 heroku[router]: at=info method=GET path="/bower_components/angular-route/angular-route.js" host=my-app.herokuapp.com request_id=57e70deb-f0c4-4cbf-8d34-46ee52688b08 fwd="92.40.249.7" dyno=web.1 connect=0ms service=1ms status=404 bytes=258
    2017-02-09T12:26:06.003504+00:00 heroku[router]: at=info method=GET path="/bower_components/lodash/dist/lodash.js" host=my-app.herokuapp.com request_id=049c759b-f7fb-4e5d-9b87-ed26afa07ca8 fwd="92.40.249.7" dyno=web.1 connect=1ms service=2ms status=404 bytes=249

but when I run the url it does not show the app but only what looks like the readme file instead of the index.html file. My app works fine locally and is using express.js and angular

Thanks

Ok so I realised that I was not loading the bower components and therefore angular or jquery etc. was being loaded.

I found the fix for it here http://xseignard.github.io/2013/02/18/use-bower-with-heroku/

and here https://devcenter.heroku.com/articles/node-best-practices

I added bower as a dependency in the package.json file and a postinstall

"scripts": {
  "postinstall": "bower install",
  "start": "node app.js"
},
"dependencies": {
  "bower": "1.8.0"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM