【问题标题】:Application Error on Heroku Node AppHeroku 节点应用程序上的应用程序错误
【发布时间】:2018-05-28 10:49:14
【问题描述】:

我最近在免费层上为 Heroku 部署了一个节点 REST API。当我部署时,它可以完美运行 30-60 秒。然后,它以应用程序错误响应。下面是 server.js 文件中的代码。

const express = require('express')
const bodyParser = require('body-parser')
const mysql = require('mysql')
var path = require('path');
var formidable = require('formidable');
var fs = require('fs');
const fileUpload = require('express-fileupload');
const cors = require('cors');

const app = express()
app.use(cors());
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
//middleware that allows reactjs app to access api from a different port
var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', "*");
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
}

app.use(allowCrossDomain);
app.use(express.static(path.join(__dirname, 'public')));
app.use(fileUpload());
app.use('/public', express.static(__dirname + '/public'));


//parse requests of Content-Type
app.use(bodyParser.urlencoded({extended:true}))
//parse requests of content-type application/json
app.use(bodyParser.json())

require("./app/routes/MainRoutes")(app)

const port = process.env.PORT || 8080
app.listen(port,"0.0.0.0",()=>{
    console.log("Server is running on port " + port )
})
app.get('/',(req,res)=>{
    console.log("hello")
    res.status(200).send({message:"Curricula API" })
})

【问题讨论】:

  • 能否添加应用程序崩溃时的错误?见Heroku logging (heroku logs)

标签: node.js rest express heroku


【解决方案1】:

您可以通过输入heroku logs查看heroku应用程序错误的原因查看此链接https://devcenter.heroku.com/articles/logging

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-17
    • 2021-10-30
    • 2013-08-25
    • 2023-03-24
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 2019-01-12
    相关资源
    最近更新 更多