繁体   English   中英

heroku:部署时应用程序未显示

[英]heroku: application not showing when deployed

这是我第一次使用节点 JS,我创建了一个应用程序并将其成功部署到 Heroku,但问题是当我在 Heroku 中打开它时出现应用程序错误。 这是 m Heroku logs ,有人可以帮我解决这个问题 PS:我在教程的帮助下实现了这个应用程序,所以我认为我没有编码问题

提前致谢

 2021-12-08T22:45:05.920222+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:45:05.920222+00:00 app[web.1]: type: 'Single', 2021-12-08T22:45:05.920223+00:00 app[web.1]: setName: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:45:05.920224+00:00 app[web.1]: stale: false, 2021-12-08T22:45:05.920224+00:00 app[web.1]: compatible: true, 2021-12-08T22:45:05.920224+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:45:05.920224+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:45:05.920225+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:45:05.920225+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:45:05.920225+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:45:05.920226+00:00 app[web.1]: } 2021-12-08T22:45:05.920226+00:00 app[web.1]: } 2021-12-08T22:45:06.067519+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:45:06.124048+00:00 heroku[web.1]: State changed from starting to crashed 2021-12-08T22:45:07.631289+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-waters-05043.herokuapp.com request_id=d072ef8a-e480-463f-a5a4-a8e2dc6726f0 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:45:07.967373+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-waters-05043.herokuapp.com request_id=d68d9288-abf3-4af7-be21-d18d5afe52a1 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:47:56.125042+00:00 heroku[web.1]: State changed from crashed to starting 2021-12-08T22:47:58.760706+00:00 heroku[web.1]: Starting process with command `npm start` 2021-12-08T22:48:00.059713+00:00 app[web.1]: 2021-12-08T22:48:00.059745+00:00 app[web.1]: > api-master-nodejs@1.0.0 start /app 2021-12-08T22:48:00.059746+00:00 app[web.1]: > node app.js 2021-12-08T22:48:00.059746+00:00 app[web.1]: 2021-12-08T22:48:14.000000+00:00 app[api]: Build started by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.216637+00:00 app[api]: Release v20 created by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.216637+00:00 app[api]: Deploy 1883c51b by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.965093+00:00 heroku[web.1]: Restarting 2021-12-08T22:48:30.000000+00:00 app[api]: Build succeeded 2021-12-08T22:48:30.572968+00:00 app[web.1]: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 2021-12-08T22:48:30.572988+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:847:32) 2021-12-08T22:48:30.572989+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10 2021-12-08T22:48:30.572989+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 2021-12-08T22:48:30.572990+00:00 app[web.1]: at new Promise (<anonymous>) 2021-12-08T22:48:30.572990+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:26:10) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 { 2021-12-08T22:48:30.572994+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:48:30.572994+00:00 app[web.1]: type: 'Single', 2021-12-08T22:48:30.572994+00:00 app[web.1]: setName: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:48:30.572996+00:00 app[web.1]: stale: false, 2021-12-08T22:48:30.572996+00:00 app[web.1]: compatible: true, 2021-12-08T22:48:30.572996+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:48:30.572996+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:48:30.572997+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:48:30.572997+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:48:30.572997+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:48:30.572998+00:00 app[web.1]: } 2021-12-08T22:48:30.572998+00:00 app[web.1]: } 2021-12-08T22:48:30.712406+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:48:31.885593+00:00 heroku[web.1]: Starting process with command `npm start` 2021-12-08T22:48:32.779803+00:00 app[web.1]: 2021-12-08T22:48:32.779817+00:00 app[web.1]: > api-master-nodejs@1.0.0 start /app 2021-12-08T22:48:32.779818+00:00 app[web.1]: > node app.js 2021-12-08T22:48:32.779818+00:00 app[web.1]: 2021-12-08T22:49:03.195533+00:00 app[web.1]: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 2021-12-08T22:49:03.195546+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:847:32) 2021-12-08T22:49:03.195548+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10 2021-12-08T22:49:03.195548+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 2021-12-08T22:49:03.195549+00:00 app[web.1]: at new Promise (<anonymous>) 2021-12-08T22:49:03.195550+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) 2021-12-08T22:49:03.195550+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:23:10) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14) 2021-12-08T22:49:03.195552+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 2021-12-08T22:49:03.195552+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 { 2021-12-08T22:49:03.195554+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:49:03.195555+00:00 app[web.1]: type: 'Single', 2021-12-08T22:49:03.195555+00:00 app[web.1]: setName: null, 2021-12-08T22:49:03.195555+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:49:03.195555+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:49:03.195556+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:49:03.195556+00:00 app[web.1]: stale: false, 2021-12-08T22:49:03.195556+00:00 app[web.1]: compatible: true, 2021-12-08T22:49:03.195557+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:49:03.195557+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:49:03.195557+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:49:03.195559+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:49:03.195559+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:49:03.195560+00:00 app[web.1]: } 2021-12-08T22:49:03.195560+00:00 app[web.1]: } 2021-12-08T22:49:03.330999+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:49:03.416601+00:00 heroku[web.1]: State changed from starting to crashed 2021-12-08T22:49:06.220751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-waters-05043.herokuapp.com request_id=8482d148-2f0c-47c0-ac57-961c9c491948 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:49:06.584198+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-waters-05043.herokuapp.com request_id=57fafd37-93e0-4273-a836-bac498cffe7d fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https

应用程序.js:

 const express = require('express'); const morgan = require('morgan'); const mongoose = require('mongoose'); const dotenv = require('dotenv'); const jwt = require('jsonwebtoken'); const http = require('http'); const multer = require("multer"); const app = express(); const server = http.createServer(app); var cors = require('cors') // corsfffffffff app.use(cors()); /************************************** Socket IO Related Start ************************************************/ // config dotenv dotenv.config(); const dbURI = process.env.MONGO_URL || "mongodb://localhost:27017/YourDB"; mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true }).then(result => server.listen(process.env.PORT || 3000) ).catch(err => console.log(err)); app.set('view engine', 'ejs'); app.use(express.json); // app.use(express.urlencoded({ extended: true })); // app.use(morgan("dev")); app.use((req, res, next) => { res.locals.path = req.path; next(); }); const subscribersRouter = require('./routes/subscribers') app.use('/subscribers', subscribersRouter) app.get("/", function(req,res){ res.send("welcome to app"); })

您的环境变量 MONGO_URL 未定义,因此它试图连接到 localhost。

  1. 登录 Heroku
  2. Go 到您的应用程序
  3. 选择设置
  4. 显示配置变量
  5. 输入 mongo 数据库的正确路径。

而不是拥有后备值,就像你有mongodb://localhost:27017/YourDB - 通常更好的是快速失败并在未定义所需变量时使用断言抛出错误。

assert(process.env.MONGO_URL, 'Missing connection string for mongo')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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