在heroku中部署的node.js应用程序出错

时间:2019-04-15 23:48:57

标签: node.js mongodb heroku heroku-cli

我正在尝试上传一个简单的node.js和mongoDB应用程序,但是我在浏览器中遇到此错误

  

内部服务器错误

这些是将应用程序上传到heroku时的消息

Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 816 bytes | 272.00 KiB/s, done.
Total 5 (delta 3), 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 10.x...
remote:        Downloading and installing node 10.15.3...
remote:        Using default npm version: 6.4.1
remote:
remote: -----> Restoring cache
remote:        - node_modules
remote:
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        audited 2550 packages in 4.651s
remote:        found 0 vulnerabilities
remote:
remote:
remote: -----> Build
remote:
remote: -----> Caching build
remote:        - node_modules
remote:
remote: -----> Pruning devDependencies
remote:        audited 2550 packages in 3.71s
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: 22.7M
remote: -----> Launching...
remote:        Released v9
remote:        https://curso-node-final.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/curso-node-final.git
   63644bb..80f72b0  master -> master

这时我想没有错误。

此时此刻,我使用heroku logs -t查看日志,并获得了该信息

2019-04-15T23:07:50.241167+00:00 app[api]: Deploy 80f72b0a by user thomascaycedo19@outlook.com
2019-04-15T23:07:50.241167+00:00 app[api]: Release v9 created by user thomascaycedo19@outlook.com
2019-04-15T23:07:50.657682+00:00 heroku[web.1]: Restarting
2019-04-15T23:07:50.674669+00:00 heroku[web.1]: State changed from up to starting
2019-04-15T23:07:51.000000+00:00 app[api]: Build succeeded
2019-04-15T23:07:51.664825+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-04-15T23:07:51.752708+00:00 heroku[web.1]: Process exited with status 143
2019-04-15T23:07:53.862592+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-15T23:07:56.538951+00:00 app[web.1]:
2019-04-15T23:07:56.538975+00:00 app[web.1]: > final@1.0.0 start /app
2019-04-15T23:07:56.538977+00:00 app[web.1]: > node server/server.js
2019-04-15T23:07:56.538978+00:00 app[web.1]:
2019-04-15T23:07:57.884159+00:00 app[web.1]: Listening to port 12865
2019-04-15T23:07:58.066216+00:00 app[web.1]: DB ONLINE
2019-04-15T23:07:58.539377+00:00 heroku[web.1]: State changed from starting to up

如您所见,数据库连接没有问题,我用邮递员进行测试,并且测试是正确的。

然后我进入浏览器加载页面,但出现错误

  

内部服务器错误

我再次检查日志,并获得此信息。

2019-04-15T23:26:05.762247+00:00 heroku[router]: at=info method=GET path="/" host=curso-node-final.herokuapp.com request_id=342b9743-e26d-4ab0-a4bb-a04457bed60b fwd="186.148.181.31" dyno=web.1 connect=0ms service=44ms status=500 bytes=404 protocol=https
2019-04-15T23:26:05.760933+00:00 app[web.1]: Error: /app/views/home.hbs: The partial head could not be found
2019-04-15T23:26:05.760955+00:00 app[web.1]: at Object.invokePartial (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:281:11)
2019-04-15T23:26:05.760957+00:00 app[web.1]: at Object.invokePartialWrapper [as invokePartial] (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
2019-04-15T23:26:05.760964+00:00 app[web.1]: at Object.eval [as main] (eval at createFunctionContext (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:5:31)
2019-04-15T23:26:05.760966+00:00 app[web.1]: at main (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
2019-04-15T23:26:05.760968+00:00 app[web.1]: at ret (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
2019-04-15T23:26:05.760970+00:00 app[web.1]: at ret (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
2019-04-15T23:26:05.760972+00:00 app[web.1]: at /app/node_modules/hbs/lib/hbs.js:63:19
2019-04-15T23:26:05.760974+00:00 app[web.1]: at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
2019-04-15T23:26:06.273916+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=curso-node-final.herokuapp.com request_id=17e543dd-f5d0-4452-8d14-b36416443e23 fwd="186.148.181.31" dyno=web.1 connect=1ms service=4ms status=404 bytes=394 protocol=https

我已经在本地测试了应用程序,没有错误。

据我所知,它找不到path = "/",但我不知道如何解决。

这是node.js的代码

const express = require('express')
const app = express();
const hbs = require('hbs');
const bcrypt = require('bcrypt');
const _ = require('underscore');
const Curso = require('../models/modelCurses');
const Estudiante = require('../models/modelStudent');
const Usuario = require('../models/modelUser');

app.use( express.static(__dirname + '../../../public/'))

//Express HBS engine
hbs.registerPartials(__dirname + '../../../views/partials');
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
    res.render('home');
})

module.exports = app;

0 个答案:

没有答案