Ошибка приложения в Heroku из-за MongoDB? - PullRequest
3 голосов
/ 29 января 2020

Я пытаюсь развернуть проект на героку. Проект может работать локально, он был успешно построен:

Ties-MBP:devconnector chengtie$ git push heroku master
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 708 bytes | 708.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:        
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:        
remote:        Resolving node version 12.x...
remote:        Downloading and installing node 12.14.1...
remote:        Using default npm version: 6.13.4
remote:        
remote: -----> Restoring cache
remote:        - node_modules
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        audited 526 packages in 2.51s
remote:        
remote:        4 packages are looking for funding
remote:          run `npm fund` for details
remote:        
remote:        found 0 vulnerabilities
remote:        
remote:        
remote: -----> Build
remote:        Running heroku-postbuild
remote:        
remote:        > devconnector@1.0.0 heroku-postbuild /tmp/build_2d10cdda70895c0ca15ac9e91acad1a9
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:        
remote:        
remote:        > core-js@2.6.11 postinstall /tmp/build_2d10cdda70895c0ca15ac9e91acad1a9/client/node_modules/babel-runtime/node_modules/core-js
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        
remote:        > core-js@3.6.4 postinstall /tmp/build_2d10cdda70895c0ca15ac9e91acad1a9/client/node_modules/core-js
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        
remote:        > core-js-pure@3.6.4 postinstall /tmp/build_2d10cdda70895c0ca15ac9e91acad1a9/client/node_modules/core-js-pure
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        added 1672 packages from 796 contributors and audited 906305 packages in 41.702s
remote:        
remote:        33 packages are looking for funding
remote:          run `npm fund` for details
remote:        
remote:        found 0 vulnerabilities
remote:        
remote:        
remote:        > client@0.1.0 build /tmp/build_2d10cdda70895c0ca15ac9e91acad1a9/client
remote:        > react-scripts build
remote:        
remote:        Creating an optimized production build...
remote:        Compiled with warnings.
remote:        
remote:        ./src/components/profile/ProfileGithub.js
remote:          Line 10:6:  React Hook useEffect has a missing dependency: 'username'. Either include it or remove the dependency array  react-hooks/exhaustive-deps
remote:        
remote:        ./src/components/post/Post.js
remote:          Line 14:6:  React Hook useEffect has a missing dependency: 'match.params.id'. Either include it or remove the dependency array  react-hooks/exhaustive-deps
remote:        
remote:        ./src/actions/post.js
remote:          Line 158:11:  'res' is assigned a value but never used  no-unused-vars
remote:        
remote:        ./src/components/profiles/ProfileItem.js
remote:          Line 1:17:  'Fragment' is defined but never used     no-unused-vars
remote:          Line 1:27:  'useEffect' is defined but never used    no-unused-vars
remote:          Line 4:10:  'connect' is defined but never used      no-unused-vars
remote:          Line 5:8:   'Spinner' is defined but never used      no-unused-vars
remote:          Line 6:10:  'getProfiles' is defined but never used  no-unused-vars
remote:        
remote:        ./src/components/profile/Profile.js
remote:          Line 21:6:  React Hook useEffect has a missing dependency: 'match.params.id'. Either include it or remove the dependency array  react-hooks/exhaustive-deps
remote:        
remote:        ./src/actions/alert.js
remote:          Line 4:10:  'STATES' is defined but never used  no-unused-vars
remote:        
remote:        ./src/store.js
remote:          Line 5:8:  'App' is defined but never used  no-unused-vars
remote:        
remote:        ./src/components/profile-forms/EditProfile.js
remote:          Line 71:6:  React Hook useEffect has missing dependencies: 'profile.bio', 'profile.company', 'profile.githubusername', 'profile.location', 'profile.skills', 'profile.social', 'profile.status', and 'profile.website'. Either include them or remove the dependency array. If 'setFormData' needs the current value of 'profile.company', you can also switch to useReducer instead of useState and read 'profile.company' in the reducer  react-hooks/exhaustive-deps
remote:        
remote:        Search for the keywords to learn more about each warning.
remote:        To ignore, add // eslint-disable-next-line to the line before.
remote:        
remote:        File sizes after gzip:
remote:        
remote:          193.04 KB  build/static/js/2.6988f640.chunk.js
remote:          18.01 KB   build/static/js/main.7cad9bf2.chunk.js
remote:          1.83 KB    build/static/css/main.11b62bc3.chunk.css
remote:          772 B      build/static/js/runtime-main.cea588d5.js
remote:        
remote:        The project was built assuming it is hosted at the server root.
remote:        You can control this with the homepage field in your package.json.
remote:        For example, add this to build it for GitHub Pages:
remote:        
remote:          "homepage" : "http://myname.github.io/myapp",
remote:        
remote:        The build folder is ready to be deployed.
remote:        You may serve it with a static server:
remote:        
remote:          yarn global add serve
remote:          serve -s build
remote:        
remote:        Find out more about deployment here:
remote:        
remote:          bit.ly/CRA-deploy
remote:        
remote:        
remote: -----> Caching build
remote:        - node_modules
remote:        
remote: -----> Pruning devDependencies
remote:        removed 125 packages and audited 309 packages in 3.58s
remote:        
remote:        1 package is looking for funding
remote:          run `npm fund` for details
remote:        
remote:        found 0 vulnerabilities
remote:        
remote:        
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 65M
remote: -----> Launching...
remote:        Released v4
remote:        https://ancient-shelf-71404.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/ancient-shelf-71404.git
   e0ea014..b56f9ce  master -> master

Однако https://ancient-shelf-71404.herokuapp.com/ показывает ошибку.

enter image description here

Вот результат heroku logs --tail:

2020-01-29T09:50:20.000000+00:00 app[api]: Build started by user chengtie@gmail.com
2020-01-29T09:52:30.353917+00:00 app[api]: Deploy e0ea014a by user chengtie@gmail.com
2020-01-29T09:52:30.368629+00:00 app[api]: Scaled to web@1:Free by user chengtie@gmail.com
2020-01-29T09:52:30.353917+00:00 app[api]: Release v3 created by user chengtie@gmail.com
2020-01-29T09:52:32.000000+00:00 app[api]: Build succeeded
2020-01-29T09:52:39.870533+00:00 heroku[web.1]: Starting process with command `npm start`
2020-01-29T09:52:42.529914+00:00 app[web.1]: 
2020-01-29T09:52:42.529947+00:00 app[web.1]: > devconnector@1.0.0 start /app
2020-01-29T09:52:42.529949+00:00 app[web.1]: > node server
2020-01-29T09:52:42.529951+00:00 app[web.1]: 
2020-01-29T09:52:43.030242+00:00 app[web.1]: the options [userFindAndModify] is not supported
2020-01-29T09:52:43.135493+00:00 app[web.1]: express-validator: requires to express-validator/check are deprecated.You should just use require("express-validator") instead.
2020-01-29T09:52:43.304468+00:00 app[web.1]: Server started on port 24212
2020-01-29T09:52:43.339505+00:00 app[web.1]: (node:23) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2020-01-29T09:52:43.736912+00:00 heroku[web.1]: State changed from starting to up
2020-01-29T09:52:44.728064+00:00 app[web.1]: failed to connect to server [cluster0-shard-00-01-jnhgq.azure.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to cluster0-shard-00-01-jnhgq.azure.mongodb.net:27017 closed
2020-01-29T09:52:44.728074+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:372:9)
2020-01-29T09:52:44.728077+00:00 app[web.1]: at Object.onceWrapper (events.js:313:26)
2020-01-29T09:52:44.728079+00:00 app[web.1]: at TLSSocket.emit (events.js:223:5)
2020-01-29T09:52:44.728081+00:00 app[web.1]: at net.js:664:12
2020-01-29T09:52:44.728083+00:00 app[web.1]: at TCP.done (_tls_wrap.js:481:7) {
2020-01-29T09:52:44.728085+00:00 app[web.1]: name: 'MongoNetworkError',
2020-01-29T09:52:44.728087+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-01-29T09:52:44.728089+00:00 app[web.1]: }]
2020-01-29T09:52:44.745668+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-29T09:52:44.746170+00:00 app[web.1]: npm ERR! errno 1
2020-01-29T09:52:44.748403+00:00 app[web.1]: npm ERR! devconnector@1.0.0 start: `node server`
2020-01-29T09:52:44.748626+00:00 app[web.1]: npm ERR! Exit status 1
2020-01-29T09:52:44.748985+00:00 app[web.1]: npm ERR!
2020-01-29T09:52:44.749178+00:00 app[web.1]: npm ERR! Failed at the devconnector@1.0.0 start script.
2020-01-29T09:52:44.749370+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-01-29T09:52:44.763478+00:00 app[web.1]: 
2020-01-29T09:52:44.763782+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-01-29T09:52:44.763957+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-01-29T09_52_44_751Z-debug.log
2020-01-29T09:52:44.900668+00:00 heroku[web.1]: State changed from up to crashed
2020-01-29T09:52:44.904360+00:00 heroku[web.1]: State changed from crashed to starting
2020-01-29T09:52:44.883640+00:00 heroku[web.1]: Process exited with status 1
2020-01-29T09:52:55.677596+00:00 heroku[web.1]: Starting process with command `npm start`
2020-01-29T09:52:58.421225+00:00 app[web.1]: 
2020-01-29T09:52:58.421243+00:00 app[web.1]: > devconnector@1.0.0 start /app
2020-01-29T09:52:58.421244+00:00 app[web.1]: > node server
2020-01-29T09:52:58.421246+00:00 app[web.1]: 
2020-01-29T09:52:59.055220+00:00 app[web.1]: the options [userFindAndModify] is not supported
2020-01-29T09:52:59.216486+00:00 app[web.1]: express-validator: requires to express-validator/check are deprecated.You should just use require("express-validator") instead.
2020-01-29T09:52:59.465530+00:00 app[web.1]: Server started on port 49717
2020-01-29T09:52:59.501991+00:00 app[web.1]: (node:23) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2020-01-29T09:53:00.046649+00:00 heroku[web.1]: State changed from starting to up
2020-01-29T09:53:00.938222+00:00 app[web.1]: failed to connect to server [cluster0-shard-00-01-jnhgq.azure.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster0-shard-00-01-jnhgq.azure.mongodb.net:27017 closed
2020-01-29T09:53:00.938255+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:372:9)
2020-01-29T09:53:00.938259+00:00 app[web.1]: at Object.onceWrapper (events.js:313:26)
2020-01-29T09:53:00.938261+00:00 app[web.1]: at TLSSocket.emit (events.js:223:5)
2020-01-29T09:53:00.938263+00:00 app[web.1]: at net.js:664:12
2020-01-29T09:53:00.938266+00:00 app[web.1]: at TCP.done (_tls_wrap.js:481:7) {
2020-01-29T09:53:00.938268+00:00 app[web.1]: name: 'MongoNetworkError',
2020-01-29T09:53:00.938270+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-01-29T09:53:00.938273+00:00 app[web.1]: }]
2020-01-29T09:53:00.954724+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-29T09:53:00.955173+00:00 app[web.1]: npm ERR! errno 1
2020-01-29T09:53:00.956874+00:00 app[web.1]: npm ERR! devconnector@1.0.0 start: `node server`
2020-01-29T09:53:00.957133+00:00 app[web.1]: npm ERR! Exit status 1
2020-01-29T09:53:00.957403+00:00 app[web.1]: npm ERR!
2020-01-29T09:53:00.957668+00:00 app[web.1]: npm ERR! Failed at the devconnector@1.0.0 start script.
2020-01-29T09:53:00.957894+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-01-29T09:53:00.967799+00:00 app[web.1]: 
2020-01-29T09:53:00.968049+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-01-29T09:53:00.968243+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-01-29T09_53_00_959Z-debug.log
2020-01-29T09:53:01.058482+00:00 heroku[web.1]: State changed from up to crashed
2020-01-29T09:53:01.041360+00:00 heroku[web.1]: Process exited with status 1
2020-01-29T09:53:01.411353+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ancient-shelf-71404.herokuapp.com request_id=cda60434-e53d-4f35-a3c7-778f7a9481a3 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:53:02.219416+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ancient-shelf-71404.herokuapp.com request_id=098c8b5f-7c75-4330-b5b3-4b4295598787 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:53:46.942378+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/%20deployed%20to%20Heroku" host=ancient-shelf-71404.herokuapp.com request_id=4ec43208-89e8-4db5-8391-33b99a490866 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:53:47.393982+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ancient-shelf-71404.herokuapp.com request_id=4653c947-764c-47ea-9653-5ae5b8813a29 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:55:50.234324+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ancient-shelf-71404.herokuapp.com request_id=c58225cf-585c-4290-906f-54820900eee4 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:55:50.686349+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ancient-shelf-71404.herokuapp.com request_id=a1fce16b-9952-4489-8a79-72b5a1855d7a fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:58:24.907640+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ancient-shelf-71404.herokuapp.com request_id=0d0ca80c-ea3a-4c8d-b930-8ea7f69fa64b fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:58:25.349389+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ancient-shelf-71404.herokuapp.com request_id=aad9749e-a961-4a49-a4f7-3aff58aada4a fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:58:54.771239+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ancient-shelf-71404.herokuapp.com request_id=4302a52d-553a-4be5-ac4d-b2acb61cce93 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https
2020-01-29T09:58:55.211610+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ancient-shelf-71404.herokuapp.com request_id=eb5f47a0-0b37-44f1-93cc-4b3b630ecc07 fwd="176.144.215.193" dyno= connect= service= status=503 bytes= protocol=https

Я использую MongoDB Atlas. Вот production.json:

{
    "mongoURI": "mongodb+srv://cheng123:...@cluster0-jnhgq.azure.mongodb.net/test?retryWrites=true&w=majority",
    "jwtSecret": "mysecrettoken",
    "githubClientId": ...,
    "githubSecret": ...
}

Кто-нибудь знает в чем дело?

Ответы [ 2 ]

2 голосов
/ 06 февраля 2020

Звучит так, как будто вы заблокированы брандмауэром.

MongoDb Atlas рекомендует использовать белые списки IP-адресов как одну из функций безопасности - вы можете увидеть, настроено ли это на портале в настройках безопасности кластера. Если он настроен (и не использует подстановочный знак 0.0.0.0), вам необходимо добавить диапазон IP-адресов вашего сервера в белый список. См. https://docs.atlas.mongodb.com/security-whitelist/

* Отказ от ответственности - я не работаю с Heroku, поэтому я не уверен, нужно ли вам открывать порт 27017 для вашего приложения. Эта статья может быть полезна, если ваш экземпляр Heroku имеет динамические c IP-адреса - https://www.mongodb.com/blog/post/integrating-mongodb-atlas-with-heroku-private-spaces

0 голосов
/ 07 февраля 2020

Возможно, что вы неправильно настроили mLab в heroku, вы должны изменить URI, который вам дает heroku, на mongoAtlas. Как я уже говорил, это "MONGOLAB_URI", который вы должны изменить, проверьте следующее изображение.

Настройки MLab

Надеюсь, это исправит вашу ошибку, если это не так не работает, проверьте эту страницу (https://docs.mlab.com/connecting/). Даже если это не помогло, прочитайте часть заявления об отказе от ответственности.

  • Отказ от ответственности - Чтобы получить помощь в будущем, отправьте часть своего кода подключения node.js и mongoDB.
...