Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems deploying Express to Heroku #222

Closed
mattb5 opened this issue Aug 2, 2016 · 2 comments
Closed

Problems deploying Express to Heroku #222

mattb5 opened this issue Aug 2, 2016 · 2 comments

Comments

@mattb5
Copy link

mattb5 commented Aug 2, 2016

Following this tutorial on deploying express to Heroku :

https://devcenter.heroku.com/articles/getting-started-with-nodejs#deploy-the-app

Also am referring to issues opened in group project.

Upon running git push heroku master, i'm getting the build succeeded message! I've connected my front end to heroku URL that was created and I'm receiving this error in my console:

# edited by @jrhorn424 - please use "preview" to ensure correct format of your issue
localhost/:1 XMLHttpRequest cannot load https://protected-island-27507.herokuapp.com//sign-in. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 503.
2016-08-02 10:56:03.738 jquery.js:9175 XHR failed loading: POST "https://protected-island-27507.herokuapp.com//sign-in".send @ jquery.js:9175ajax @ jquery.js:8656signIn @ api.js:20onSignIn @ events.js:21dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549

Running the heroku log --tails command, I see this:

# edited by @jrhorn424 - please use "preview" to ensure correct format of your issue
2016-08-02T14:40:23.317703+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="//matches/" host=protected-island-27507.herokuapp.com request_id=cdebe02e-dedd-4848-ac62-7d23729c640b fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:40:32.357587+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="//sign-up" host=protected-island-27507.herokuapp.com request_id=7d9067ad-3d9b-44fe-be0b-0d318ca2ca30 fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:40:40.954171+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="//sign-up" host=protected-island-27507.herokuapp.com request_id=5f66e0c2-d796-416b-b6a7-1601a88241e5 fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:41:21.782300+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=protected-island-27507.herokuapp.com request_id=7d07a6b4-611c-445f-9013-6d2e5cca9ef3 fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:41:21.223111+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=protected-island-27507.herokuapp.com request_id=f678d656-c1c9-43e0-b7b3-6e96cbf14f83 fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:48:24.487269+00:00 heroku[slug-compiler]: Slug compilation finished
2016-08-02T14:48:24.487264+00:00 heroku[slug-compiler]: Slug compilation started
2016-08-02T14:48:24.318831+00:00 heroku[api]: Release v5 created by mattbuffardi@gmail.com
2016-08-02T14:48:24.318712+00:00 heroku[api]: Deploy 562eb4b by mattbuffardi@gmail.com
2016-08-02T14:48:24.837293+00:00 heroku[web.1]: State changed from crashed to starting
2016-08-02T14:48:26.285752+00:00 heroku[web.1]: Starting process with command `npm start`
2016-08-02T14:48:30.378661+00:00 app[web.1]: 
2016-08-02T14:48:30.378679+00:00 app[web.1]: > Tennis-Matchrr@0.1.0 start /app
2016-08-02T14:48:30.378681+00:00 app[web.1]: 
2016-08-02T14:48:30.378680+00:00 app[web.1]: > ./bin/express server
2016-08-02T14:48:30.966773+00:00 app[web.1]: 
2016-08-02T14:48:30.966771+00:00 app[web.1]: let uri;
2016-08-02T14:48:30.966753+00:00 app[web.1]: /app/app/middleware/mongoose.js:10
2016-08-02T14:48:30.966777+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-08-02T14:48:30.966775+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-08-02T14:48:30.966778+00:00 app[web.1]:     at /app/lib/wiring/loader.js:13:39
2016-08-02T14:48:30.966772+00:00 app[web.1]:        ^
2016-08-02T14:48:30.966779+00:00 app[web.1]:     at Array.forEach (native)
2016-08-02T14:48:30.966780+00:00 app[web.1]:     at fs.readdirSync.filter.entry.forEach (/app/lib/wiring/loader.js:12:5)
2016-08-02T14:48:30.966778+00:00 app[web.1]:     at require (internal/module.js:12:17)
2016-08-02T14:48:30.966774+00:00 app[web.1]:     at exports.runInThisContext (vm.js:53:16)
2016-08-02T14:48:30.990599+00:00 app[web.1]: 
2016-08-02T14:48:30.966777+00:00 app[web.1]:     at Module.require (module.js:353:17)
2016-08-02T14:48:30.966773+00:00 app[web.1]: SyntaxError: Identifier 'uri' has already been declared
2016-08-02T14:48:31.000130+00:00 app[web.1]: npm ERR! node v4.4.0
2016-08-02T14:48:30.999894+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-08-02T14:48:30.966775+00:00 app[web.1]:     at Module._compile (module.js:373:25)
2016-08-02T14:48:31.000862+00:00 app[web.1]: npm ERR! npm  v2.14.20
2016-08-02T14:48:31.001565+00:00 app[web.1]: npm ERR! 
2016-08-02T14:48:31.001239+00:00 app[web.1]: npm ERR! Tennis-Matchrr@0.1.0 start: `./bin/express server`
2016-08-02T14:48:31.001067+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-08-02T14:48:30.999513+00:00 app[web.1]: npm ERR! Linux 3.13.0-91-generic
2016-08-02T14:48:31.002222+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-08-02T14:48:31.002045+00:00 app[web.1]: npm ERR! not with npm itself.
2016-08-02T14:48:31.001722+00:00 app[web.1]: npm ERR! Failed at the Tennis-Matchrr@0.1.0 start script './bin/express server'.
2016-08-02T14:48:31.001391+00:00 app[web.1]: npm ERR! Exit status 1
2016-08-02T14:48:31.001887+00:00 app[web.1]: npm ERR! This is most likely a problem with the Tennis-Matchrr package,
2016-08-02T14:48:30.966776+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-08-02T14:48:31.002993+00:00 app[web.1]: npm ERR! 
2016-08-02T14:48:31.003297+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-08-02T14:48:31.002663+00:00 app[web.1]: npm ERR!     npm bugs Tennis-Matchrr
2016-08-02T14:48:31.002520+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-08-02T14:48:31.008093+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-08-02T14:48:31.002841+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-08-02T14:48:31.008092+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-08-02T14:48:31.003137+00:00 app[web.1]: npm ERR!     npm owner ls Tennis-Matchrr
2016-08-02T14:48:31.002383+00:00 app[web.1]: npm ERR!     ./bin/express server
2016-08-02T14:48:31.007766+00:00 app[web.1]: 
2016-08-02T14:48:31.104616+00:00 heroku[web.1]: Process exited with status 1
2016-08-02T14:48:31.141143+00:00 heroku[web.1]: State changed from starting to crashed
2016-08-02T14:48:31.142225+00:00 heroku[web.1]: State changed from crashed to starting
2016-08-02T14:48:33.295931+00:00 heroku[web.1]: Starting process with command `npm start`
2016-08-02T14:48:37.056889+00:00 app[web.1]: 
2016-08-02T14:48:37.056904+00:00 app[web.1]: > Tennis-Matchrr@0.1.0 start /app
2016-08-02T14:48:37.056905+00:00 app[web.1]: > ./bin/express server
2016-08-02T14:48:37.056905+00:00 app[web.1]: 
2016-08-02T14:48:37.416050+00:00 app[web.1]: 
2016-08-02T14:48:37.416038+00:00 app[web.1]: /app/app/middleware/mongoose.js:10
2016-08-02T14:48:37.416051+00:00 app[web.1]:     at exports.runInThisContext (vm.js:53:16)
2016-08-02T14:48:37.416052+00:00 app[web.1]:     at Module._compile (module.js:373:25)
2016-08-02T14:48:37.416051+00:00 app[web.1]: SyntaxError: Identifier 'uri' has already been declared
2016-08-02T14:48:37.416053+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:416:10)
2016-08-02T14:48:37.416053+00:00 app[web.1]:     at Module.load (module.js:343:32)
2016-08-02T14:48:37.416049+00:00 app[web.1]:        ^
2016-08-02T14:48:37.416048+00:00 app[web.1]: let uri;
2016-08-02T14:48:37.416055+00:00 app[web.1]:     at Module.require (module.js:353:17)
2016-08-02T14:48:37.416057+00:00 app[web.1]:     at Array.forEach (native)
2016-08-02T14:48:37.428070+00:00 app[web.1]: 
2016-08-02T14:48:37.416055+00:00 app[web.1]:     at require (internal/module.js:12:17)
2016-08-02T14:48:37.416058+00:00 app[web.1]:     at fs.readdirSync.filter.entry.forEach (/app/lib/wiring/loader.js:12:5)
2016-08-02T14:48:37.439716+00:00 app[web.1]: npm ERR! npm  v2.14.20
2016-08-02T14:48:37.439994+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-08-02T14:48:37.444032+00:00 app[web.1]: npm ERR! Tennis-Matchrr@0.1.0 start: `./bin/express server`
2016-08-02T14:48:37.444034+00:00 app[web.1]: npm ERR! Exit status 1
2016-08-02T14:48:37.437994+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-08-02T14:48:37.444035+00:00 app[web.1]: npm ERR! 
2016-08-02T14:48:37.416054+00:00 app[web.1]:     at Function.Module._load (module.js:300:12)
2016-08-02T14:48:37.416056+00:00 app[web.1]:     at /app/lib/wiring/loader.js:13:39
2016-08-02T14:48:37.444035+00:00 app[web.1]: npm ERR! Failed at the Tennis-Matchrr@0.1.0 start script './bin/express server'.
2016-08-02T14:48:37.438500+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-08-02T14:48:37.444036+00:00 app[web.1]: npm ERR! This is most likely a problem with the Tennis-Matchrr package,
2016-08-02T14:48:37.444036+00:00 app[web.1]: npm ERR! not with npm itself.
2016-08-02T14:48:37.444037+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-08-02T14:48:37.444037+00:00 app[web.1]: npm ERR!     ./bin/express server
2016-08-02T14:48:37.444038+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-08-02T14:48:37.438812+00:00 app[web.1]: npm ERR! node v4.4.0
2016-08-02T14:48:37.444039+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-08-02T14:48:37.444039+00:00 app[web.1]: npm ERR! 
2016-08-02T14:48:37.444040+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-08-02T14:48:37.450053+00:00 app[web.1]: 
2016-08-02T14:48:37.444040+00:00 app[web.1]: npm ERR!     npm owner ls Tennis-Matchrr
2016-08-02T14:48:37.450057+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-08-02T14:48:37.444038+00:00 app[web.1]: npm ERR!     npm bugs Tennis-Matchrr
2016-08-02T14:48:37.450059+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-08-02T14:48:37.564938+00:00 heroku[web.1]: State changed from starting to crashed
2016-08-02T14:48:37.544036+00:00 heroku[web.1]: Process exited with status 1
2016-08-02T14:55:51.122877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="//matches/" host=protected-island-27507.herokuapp.com request_id=2e678521-5077-4510-b014-9551d64b37f1 fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:55:59.955470+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="//sign-up" host=protected-island-27507.herokuapp.com request_id=8b190655-c400-41b7-95a6-f24cd0b17b4e fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
2016-08-02T14:56:03.728456+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="//sign-in" host=protected-island-27507.herokuapp.com request_id=77fa7eba-d4cd-4188-89f8-e3abb5eb9eea fwd="74.118.24.163" dyno= connect= service= status=503 bytes=
@berziiii berziiii self-assigned this Aug 2, 2016
@mattb5
Copy link
Author

mattb5 commented Aug 2, 2016

Do these steps, in order, to deploy express api template to heroku.  

— sign up for mlab at mlab.com / click link in verification email  

— credit card information needs to be submitted on heroku - looks like as long as you don’t MASSIVELY populate your database, you’re credit card will not be charged

- make sure you have heroku tool belt installed for MAC

— go into your express-api-template to app/middleware/mongoose.js and replace the following line: 

```js
 const uri = process.env.MONGOLAB_URI || 'mongodb://localhost/<your project name>';

with this new block:

let uri;
if (process.env.NODE_ENV === 'production') {
  uri = process.env.MONGODB_URI;
} else {
  uri = 'mongodb://localhost/<your project name>’;
} 
  • commit to your local master branch
  • in terminal, run : heroku create
  • in terminal run : git remote -v - make sure that heroku remote repo is pointing towards the newly created heroic url. IF NOT, run this in terminal : git remote set-url heroku
  • go to your heroku dashboard, click on newly created heroku app, click on resources tab, search for and add mLab for Add-Ons
  • in terminal, run : git push heroku master (should build your site)

— in terminal, run : heroku config:set NODE_ENV=“production” (should add a new key value pair in resources tab, under “reveal config tags” in heroku dashboard

  • in terminal, run : echo SECRET_KEY=$(/usr/local/opt/openssl/bin/openssl rand -base64 66 | tr -d '\n') (this should generate a secret_key)

— in terminal run: heroku config:set <copy and paste secret_key generated from last command> . should start with “SECRET_KEY and span about 40 randomized characters”

in terminal, run: heroku restart

in terminal, run: heroku open

be sure to change, in your client side app, the app.host value to point to your heroku server URL


THIS SHOULD DEPLOY YOUR EXPRESS API TO HEROKU.   TALK TO ME IF YOU HAVE PROBLEMS :)  -matt buffardi

@berziiii
Copy link

berziiii commented Aug 16, 2016

Updated deployment guide:

Do these steps, in order, to deploy express api template to heroku.  

 sign up for mlab at mlab.com / click link in verification email  

 credit card information needs to be submitted on heroku - looks like as long as you don’t MASSIVELY populate your database, you’re credit card will not be charged

- make sure you have heroku tool belt installed for MAC

 go into your express-api-template to `app/middleware/mongoose.js` and replace the following line: 
const uri = process.env.MONGOLAB_URI || 'mongodb://localhost/<your project name>';

with

const uri = process.env.MONGODB_URI || 'mongodb://localhost/<your project name>';
  • commit to your local master branch
  • in terminal, run : heroku create
  • in terminal run : git remote -v - make sure that heroku remote repo is pointing towards the newly created heroic url. IF NOT, run this in terminal : git remote set-url heroku <copy and paste the URL of your heroiku hosted app that you just created in step above>
  • go to your heroku dashboard, click on newly created heroku app, click on resources tab, search for and add mLab for Add-Ons
  • in terminal, run : git push heroku master (should build your site)
  • due to the first line of code in the server.js file, the default deployment environment will be production
  • in terminal, run : echo SECRET_KEY=$(/usr/local/opt/openssl/bin/openssl rand -base64 66 | tr -d '\n') this should generate a secret_key
  • in terminal run: heroku config:set <copy and paste secret_key generated from last command> . should start with “SECRET_KEY and span about 40 randomized characters”
  • you need to set your client url so that your deployed API will ONLY accept requests from the correct domain. IF you're client is deployed on Github, your url will be:
    https://<% github username %>.github.io
  • Set your client url by:
    heroku config:set CLIENT_URL="https://<% github username %>.github.io"
  • You should have three config variables set in heroku (heroku>settings>config vars): MONGODB_URI, SECRET_KEY, CLIENT_URL
  • Once all three of these are set, run in terminal: heroku restart
  • Then in terminal, run: heroku open

You should see JSON of your home page saying:

{
    title: <% TITLE OF APP %>,
    environment: 'production'
}

If you see Application Error, you may have missed a step!

be sure to change, in your client side app, the app.host value to point to your heroku server URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants