运行 时如何消除 heroku 中的应用程序错误
How to get rid of application error in heroku when running
我在 6 个月前第一次在 Heroku 上部署了这个应用程序,运行 很好。它在本地主机上仍然 运行 正常,但现在当我尝试使用相同的 heroku link 它显示应用程序错误。
这是我的日志:
heroku logs --tail
2021-11-22T21:25:37.247493+00:00 heroku[web.1]: Restarting
2021-11-22T21:25:37.291674+00:00 heroku[web.1]: State changed from up to starting
2021-11-22T21:25:38.213115+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-11-22T21:25:38.434284+00:00 heroku[web.1]: Process exited with status 143
2021-11-22T21:25:39.432521+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-11-22T21:25:40.721334+00:00 app[web.1]: Database_URL undefined
2021-11-22T21:25:40.722187+00:00 app[web.1]: Server has started
2021-11-22T21:25:41.145424+00:00 heroku[web.1]: State changed from starting to up
2021-11-22T21:26:10.715356+00:00 app[web.1]: connect ECONNREFUSED 127.0.0.1:27017
2021-11-22T21:26:20.762822+00:00 heroku[router]: at=info method=GET path="/" host=sleepy-basin-23202.herokuapp.com request_id=9145c837-b0b8-409e-af04-38431cef02a5 fwd="47.15.8.93" dyno=web.1 connect=0ms service=12ms status=304 bytes=151 protocol=https
2021-11-22T21:26:21.119967+00:00 heroku[router]: at=info method=GET path="/style.css" host=sleepy-basin-23202.herokuapp.com request_id=7cd5ff7a-a627-4f97-a28f-b4f73b08b463
fwd="47.15.8.93" dyno=web.1 connect=0ms service=9ms status=200 bytes=4543 protocol=https
2021-11-22T21:26:21.123105+00:00 heroku[router]: at=info method=GET path="/script.js" host=sleepy-basin-23202.herokuapp.com request_id=3176b0d8-80b4-4c6c-a389-cc786bbd0e0f
fwd="47.15.8.93" dyno=web.1 connect=0ms service=7ms status=404 bytes=392 protocol=https
2021-11-22T21:26:21.452457+00:00 heroku[router]: at=info method=GET path="/script.js" host=sleepy-basin-23202.herokuapp.com request_id=cbdc660f-90e1-443b-8b2d-2f255018b63d
fwd="47.15.8.93" dyno=web.1 connect=0ms service=2ms status=404 bytes=392 protocol=https
2021-11-22T21:26:22.904249+00:00 heroku[router]: at=info method=POST path="/view" host=sleepy-basin-23202.herokuapp.com request_id=3a4c38b1-5798-490e-bc1b-73338fc18cf5 fwd="47.15.8.93" dyno=web.1 connect=0ms service=13ms status=302 bytes=246 protocol=https
2021-11-22T21:26:33.202949+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseError: Operation `users.find()` buffering timed out after 10000ms
2021-11-22T21:26:33.202957+00:00 app[web.1]: at Timeout.<anonymous> (/app/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
2021-11-22T21:26:33.202958+00:00 app[web.1]: at listOnTimeout (internal/timers.js:554:17)
2021-11-22T21:26:33.202959+00:00 app[web.1]: at processTimers (internal/timers.js:497:7)
2021-11-22T21:26:33.202960+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-11-22T21:26:33.203001+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2021-11-22T21:26:33.203100+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are
not handled will terminate the Node.js process with a non-zero exit code.
2021-11-22T21:26:53.190725+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/view" host=sleepy-basin-23202.herokuapp.com request_id=23595d4a-6e69-48cf-a1ce-2ef12ce13815 fwd="47.15.8.93" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
它找不到你的数据库Url检查你的环境配置
这里的信息不多,但是我看到了
Database_URL undefined
在您的日志中。假设您正在使用像 Heroku Postgres 这样的 Heroku 数据库插件,您的数据库 URL 将在一个名为 DATABASE_URL
的变量中定义。大小写很重要:DATABASE_URL
和 Database_URL
是不同的东西。
请更新您的代码以使用 DATABASE_URL
。
请注意,在 Windows 上,环境变量名称 不 区分大小写。如果您使用 Windows 进行本地开发,这就是这可能在本地工作而不在 Heroku 上工作的原因之一。
我在 6 个月前第一次在 Heroku 上部署了这个应用程序,运行 很好。它在本地主机上仍然 运行 正常,但现在当我尝试使用相同的 heroku link 它显示应用程序错误。
这是我的日志:
heroku logs --tail
2021-11-22T21:25:37.247493+00:00 heroku[web.1]: Restarting
2021-11-22T21:25:37.291674+00:00 heroku[web.1]: State changed from up to starting
2021-11-22T21:25:38.213115+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-11-22T21:25:38.434284+00:00 heroku[web.1]: Process exited with status 143
2021-11-22T21:25:39.432521+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-11-22T21:25:40.721334+00:00 app[web.1]: Database_URL undefined
2021-11-22T21:25:40.722187+00:00 app[web.1]: Server has started
2021-11-22T21:25:41.145424+00:00 heroku[web.1]: State changed from starting to up
2021-11-22T21:26:10.715356+00:00 app[web.1]: connect ECONNREFUSED 127.0.0.1:27017
2021-11-22T21:26:20.762822+00:00 heroku[router]: at=info method=GET path="/" host=sleepy-basin-23202.herokuapp.com request_id=9145c837-b0b8-409e-af04-38431cef02a5 fwd="47.15.8.93" dyno=web.1 connect=0ms service=12ms status=304 bytes=151 protocol=https
2021-11-22T21:26:21.119967+00:00 heroku[router]: at=info method=GET path="/style.css" host=sleepy-basin-23202.herokuapp.com request_id=7cd5ff7a-a627-4f97-a28f-b4f73b08b463
fwd="47.15.8.93" dyno=web.1 connect=0ms service=9ms status=200 bytes=4543 protocol=https
2021-11-22T21:26:21.123105+00:00 heroku[router]: at=info method=GET path="/script.js" host=sleepy-basin-23202.herokuapp.com request_id=3176b0d8-80b4-4c6c-a389-cc786bbd0e0f
fwd="47.15.8.93" dyno=web.1 connect=0ms service=7ms status=404 bytes=392 protocol=https
2021-11-22T21:26:21.452457+00:00 heroku[router]: at=info method=GET path="/script.js" host=sleepy-basin-23202.herokuapp.com request_id=cbdc660f-90e1-443b-8b2d-2f255018b63d
fwd="47.15.8.93" dyno=web.1 connect=0ms service=2ms status=404 bytes=392 protocol=https
2021-11-22T21:26:22.904249+00:00 heroku[router]: at=info method=POST path="/view" host=sleepy-basin-23202.herokuapp.com request_id=3a4c38b1-5798-490e-bc1b-73338fc18cf5 fwd="47.15.8.93" dyno=web.1 connect=0ms service=13ms status=302 bytes=246 protocol=https
2021-11-22T21:26:33.202949+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseError: Operation `users.find()` buffering timed out after 10000ms
2021-11-22T21:26:33.202957+00:00 app[web.1]: at Timeout.<anonymous> (/app/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
2021-11-22T21:26:33.202958+00:00 app[web.1]: at listOnTimeout (internal/timers.js:554:17)
2021-11-22T21:26:33.202959+00:00 app[web.1]: at processTimers (internal/timers.js:497:7)
2021-11-22T21:26:33.202960+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-11-22T21:26:33.203001+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2021-11-22T21:26:33.203100+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are
not handled will terminate the Node.js process with a non-zero exit code.
2021-11-22T21:26:53.190725+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/view" host=sleepy-basin-23202.herokuapp.com request_id=23595d4a-6e69-48cf-a1ce-2ef12ce13815 fwd="47.15.8.93" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
它找不到你的数据库Url检查你的环境配置
这里的信息不多,但是我看到了
Database_URL undefined
在您的日志中。假设您正在使用像 Heroku Postgres 这样的 Heroku 数据库插件,您的数据库 URL 将在一个名为 DATABASE_URL
的变量中定义。大小写很重要:DATABASE_URL
和 Database_URL
是不同的东西。
请更新您的代码以使用 DATABASE_URL
。
请注意,在 Windows 上,环境变量名称 不 区分大小写。如果您使用 Windows 进行本地开发,这就是这可能在本地工作而不在 Heroku 上工作的原因之一。