Node.js Heroku应用程序在本地工作,但在部署时无法工作

Node.js Heroku应用程序在本地工作,但在部署时无法工作,node.js,express,heroku,Node.js,Express,Heroku,我正在尝试将一个应用程序上传到heroku,但我似乎不明白为什么我的应用程序可以通过nodemon或heroku local在本地完美运行,但一旦部署到heroku,它将显示“内部服务器错误”。这似乎与ejs或文件路径有关 这是heroku的日志显示的内容 2019-12-10T11:01:15.750370+00:00 app[web.1]: Error: /app/views/home.ejs:1 2019-12-10T11:01:15.750381+00:00 app[web.1]: &

我正在尝试将一个应用程序上传到heroku,但我似乎不明白为什么我的应用程序可以通过nodemon或heroku local在本地完美运行,但一旦部署到heroku,它将显示“内部服务器错误”。这似乎与ejs或文件路径有关

这是heroku的日志显示的内容

2019-12-10T11:01:15.750370+00:00 app[web.1]: Error: /app/views/home.ejs:1
2019-12-10T11:01:15.750381+00:00 app[web.1]:  >> 1| <%- include("partials/header")-%>
2019-12-10T11:01:15.750383+00:00 app[web.1]:     2| 
2019-12-10T11:01:15.750385+00:00 app[web.1]:     3| <div class="container-fluid" id="homePage">
2019-12-10T11:01:15.750386+00:00 app[web.1]:     4| 
2019-12-10T11:01:15.750387+00:00 app[web.1]: 
2019-12-10T11:01:15.750389+00:00 app[web.1]: Could not find the include file "partials/header"
2019-12-10T11:01:15.750390+00:00 app[web.1]:     at getIncludePath (/app/node_modules/ejs/lib/ejs.js:165:13)
2019-12-10T11:01:15.750391+00:00 app[web.1]:     at includeFile (/app/node_modules/ejs/lib/ejs.js:291:19)
2019-12-10T11:01:15.750392+00:00 app[web.1]:     at include (/app/node_modules/ejs/lib/ejs.js:680:16)
2019-12-10T11:01:15.750394+00:00 app[web.1]:     at eval (/app/views/home.ejs:10:17)
2019-12-10T11:01:15.750395+00:00 app[web.1]:     at home (/app/node_modules/ejs/lib/ejs.js:682:17)
2019-12-10T11:01:15.750396+00:00 app[web.1]:     at tryHandleCache (/app/node_modules/ejs/lib/ejs.js:254:36)
2019-12-10T11:01:15.750398+00:00 app[web.1]:     at View.exports.renderFile [as engine] (/app/node_modules/ejs/lib/ejs.js:485:10)
2019-12-10T11:01:15.750400+00:00 app[web.1]:     at View.render (/app/node_modules/express/lib/view.js:135:8)
2019-12-10T11:01:15.750401+00:00 app[web.1]:     at tryRender (/app/node_modules/express/lib/application.js:640:10)
2019-12-10T11:01:15.750402+00:00 app[web.1]:     at Function.render (/app/node_modules/express/lib/application.js:592:3)
2019-12-10T11:01:15.745815+00:00 heroku[router]: at=info method=GET path="/" host=voila-va.herokuapp.com request_id=4fca84a8-f079-4b85-8eae-860887f3de01 fwd="212.139.199.181" dyno=web.1 connect=1ms service=3ms status=500 bytes=404 protocol=https

错误表示找不到视图的一部分,名为“partials/header”。。。包括了吗?我包括了页眉和页脚,它们在本地服务器上工作,但在部署时不起作用。我刚刚更改了app.js中的几行,以与此线程中描述的express 4.x保持一致。它仍然会在heroku日志上抛出相同的错误,但在本地也可以工作。因此,只需通过“include It”检查home.ejs页面中的
?仍然存在相同的问题。如果我使用或不使用“.ejs”,这似乎没有什么区别。你可能需要告诉它它的位置,以及到这个文件的完整路径
//jshint esversion:6

const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const nodemailer = require('nodemailer');
// const exphbs = require("express-handlebars");#
const csp = require('express-csp-header');
const app = express();


app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
// app.use(csp({
//     policies: {
//         'default-src': [csp.SELF],
//         'script-src': [csp.SELF, csp.INLINE, 'somehost.com'],
//         'style-src': [csp.SELF, 'mystyles.net'],
//         'img-src': ['data:', 'images.com'],
//         'worker-src': [csp.NONE],
//         'block-all-mixed-content': true
//     }
// }));

app.get("/",function(req,res){
  res.render("home");
});

app.get("/services",function(req,res){
  res.render("services");
});

app.get("/pricing",function(req,res){
  res.render("pricing");
});

app.get("/about",function(req,res){
  res.render("about");
});
app.get("/contact",function(req,res){
  res.render("contact");
});

app.get("/ec",function(req,res){
  res.render("enquirycomplete");
});

app.get("/ef",function(req,res){
  res.render("enquiryfailed");
});

app.get("/privacypolicy",function(req,res){
  res.render("privacypolicy");
});


app.post("/send",function(req,res){


  const transporter = nodemailer.createTransport({
      host: 'smtp.ethereal.email',
      port: 587,
      secure: false, // true for 465, false for other ports
      auth: {
          user: 'margie.bartell@ethereal.email', // generated ethereal user
          pass: 'bSEaH13htNzHjkPZEn' // generated ethereal password
      }

  });
  const output = {
    h2:"<h2>You've got a new enquiry!</h2>",
    firstName: req.body.first_name,
    lastName: req.body.last_name,
    message: req.body.comments,
    telephone: req.body.telephone
  };
  const htmlForm =
  `<h2>You've got a new enquiry!</h2>
  <p><%=output.firstName%></p>
  <p><%=output.lastName%></p>
  <p><%=output.message%></p>
  <p><%=output.telephone</p>`;

    const mailOptions = {
        from: req.body.email, // sender address
        to: 'danieltaylor236@gmail.com', // list of receivers
        subject: 'Voila Enquiry',
        text: req.body.comments, // Subject line
        // html: output, // plain text body
        replyTo: req.body.email
    };
    transporter.sendMail(mailOptions,function(error,info){
      if (error){
         console.log("this is not working" + error);
      }else{
        console.log("EmailForm sent!" + info.response);
      }
  });
  transporter.verify(function(error, success) {
  if (error) {
    console.log(error);
    res.render("enquiryfailed");
  } else {
    console.log("Server is ready to take our messages");
    res.render("enquirycomplete");
    console.log(mailOptions);
  }
});

});



app.listen(process.env.PORT || 5000,function(){
  console.log("server started on port 3000");
});

{
  "name": "voila-website",
  "version": "1.0.0",
  "description": "Voila Website",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "heroku"
  ],
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Tayho25/Voila-website.git"
  },
  "author": "netdoodle",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Tayho25/Voila-website/issues"
  },
  "homepage": "https://github.com/Tayho25/Voila-website#readme",
  "dependencies": {
    "body-parser": "^1.19.0",
    "ejs": "^2.7.1",
    "express": "^4.17.1",
    "express-csp-header": "^2.3.2",
    "nodemailer": "^6.3.1"
  },
  "engines": {
    "node": "v12.13.1"
  }
}