【问题标题】:Application Error shows up on publishing on Heroku在 Heroku 上发布时出现应用程序错误
【发布时间】:2019-03-31 16:40:14
【问题描述】:

我已经使用heroku local web 在localhost:5000 上成功运行了MEAN 应用程序,它运行良好。使用云部署,它确实可以工作,并且出现 Application Error 消息。

server.js:

> `var express=require('express');
var path= require('path');
var bodyParser=require('body-parser');`enter code here`
var cors=require('cors');

var tasks=require('./routes/tasks');

var app=express();

var port=process.env.port || 3000;

app.use(cors());

//Static folder
app.use(express.static(path.join(__dirname,'public')));

//Body parser middle-ware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));

app.use('/api',tasks);
app.use('/**',(request,response,next)=>{
    response.status(404);
    response.send('Not Found');
    //response.sendFile(__dirname + '/public/Notfound/notfound.html');
});


app.listen(port,()=>{
    console.log('The server is running on port ' + port);
});

----------------------
here is  routes/tasks.js

var express = require('express');
var router = express.Router();

router.get('/',(request,response,next)=>{
    response.send('Index Page');
});

module.exports=router;

===============================================================
opening from local redirects me to http://localhost:5000/tasks  as per routes/tasks.js 
but the cloud version does not work, I tried to read the console but in vain

Thank you

【问题讨论】:

    标签: angular rest api mean


    【解决方案1】:

    当我将 port 替换为 PORT 时,Heroku 运行正常,但在本地仍然可以保持原样 port

    【讨论】:

      猜你喜欢
      • 2021-03-25
      • 1970-01-01
      • 2017-05-21
      • 2018-05-30
      • 2014-09-08
      • 1970-01-01
      • 2022-01-05
      • 2017-05-05
      • 2018-10-24
      相关资源
      最近更新 更多