浏览器中来自heroku的内部服务器错误

时间:2018-08-20 21:30:59

标签: heroku internal-server-error

我在heroku上运行了一个节点/快速应用程序。呈现页面时,它可以工作,但是当我尝试添加用户输入(在我的情况下,是新的帖子请求)时,在heroku日志中出现以下错误:

 status=500 

以及浏览器中的以下错误:

Internal server error

我尝试按照heroku docs中的建议在package.json文件中添加节点版本,但是该应用程序崩溃了。我至少回到了应用启动的位置。

感谢您的帮助。

下面是我的package.json和我的app.js文件:

    {
    "name": "bodhishare",
    "version": "1.0.0",
    "description": "share your wisdom",
    "main": "app.js",
    "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
    },
    "author": "Chris Galvan",
    "license": "ISC",
    "dependencies": {
    "body-parser": "^1.18.2",
    "cloudinary": "^1.9.1",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "dotenv": "^5.0.1",
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "express-session": "^1.15.6",
    "method-override": "^2.3.10",
    "moment": "^2.21.0",
     "mongoose": "^4.12.4",
     "multer": "^1.3.0",
     "nodemailer": "^4.6.4",
     "passport": "^0.4.0",
     "passport-local": "^1.0.0",
     "passport-local-mongoose": "^4.4.0",
     "request": "^2.85.0"
     }
     }

app.js

    var dotenv     = require('dotenv').config(),
    express    = require("express"),
    app        = express(),
    bodyParser = require("body-parser"), 
    mongoose   = require("mongoose"),
    flash      = require("connect-flash"),
    passport   = require("passport"),
    cookieParser = require("cookie-parser"),
    LocalStrategy = require("passport-local"),
    methodOverride = require("method-override"),
    Bodhi      = require("./models/bodhi"),
    Comment    = require("./models/comment"),
    User       = require("./models/user"),
    session = require("express-session"),
    moment = require('moment'),
    seedDB     = require("./seeds"),


    //requiring routes
    commentRoutes = require("./routes/comments"),
    bodhiRoutes   = require("./routes/bodhis"),
    indexRoutes   = require("./routes/index"),
    contactRoutes = require("./routes/contact");


    var url = process.env.DATABASEURL || 
    "mongodb://localhost/bodhishare";
     mongoose.connect(url);




    app.use(bodyParser.urlencoded({extended: true}));
    app.set("view engine", "ejs");
    app.use(express.static(__dirname + "/public"));
    app.use(methodOverride("_method"));
    app.use(cookieParser());
    app.use(session({secret: process.env.secret}));
    app.use(flash());
    //seedDB(); //uncomment this line to seed the database

    app.locals.moment = require("moment");
    //passport config
    app.use(require("express-session")({
    secret: process.env.secret,
    resave: false,
    saveUninitialized: false
    }));

    app.use(passport.initialize());
    app.use(passport.session());
    passport.use(new LocalStrategy(User.authenticate()));
    passport.serializeUser(User.serializeUser());
    passport.deserializeUser(User.deserializeUser());

    app.use(function(req, res, next){
    res.locals.currentUser = req.user;
    res.locals.error = req.flash("error");
    res.locals.success = req.flash("success");
    next();
    });

    app.use("/", indexRoutes);
    app.use("/bodhis", bodhiRoutes);
    app.use("/bodhis/:id/comments", commentRoutes);
    app.use("/contact", contactRoutes);



    app.listen(process.env.PORT, process.env.IP ,function(){
    console.log("The bodhishare server has started!");
    });

0 个答案:

没有答案