我已经使用localhost:5000
在heroku local web
上成功运行MEAN应用,并且运行正常。使用云部署,它可以正常工作,并显示应用程序错误消息。
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
答案 0 :(得分:0)
当我将def ternarySearch(f, left, right, absolutePrecision):
'''
left and right are the current bounds;
the maximum is between them
'''
if abs(right - left) < absolutePrecision:
return (left + right)/2
leftThird = (2*left + right)/3
rightThird = (left + 2*right)/3
if f(leftThird) < f(rightThird):
return ternarySearch(f, leftThird, right, absolutePrecision)
else:
return ternarySearch(f, left, rightThird, absolutePrecision)
替换为port
时,使用Heroku可以正常运行,但是在本地仍然可以将其保留为PORT