我最近在免费套餐上向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" })
})
答案 0 :(得分:1)
您可以通过键入heroku logs
查看heroku应用程序错误的原因查看此链接https://devcenter.heroku.com/articles/logging