【问题标题】:"Method Not allowed" error when trying to deploy node.js app to heroku尝试将 node.js 应用程序部署到 heroku 时出现“方法不允许”错误
【发布时间】:2018-02-18 10:46:55
【问题描述】:

尝试部署到 Heroku 时,我不断收到方法不允许错误。

日志没有太多信息:

Server is started !

 2018-02-18T01:55:03.853131+00:00 heroku[web.1]: State changed from 
 starting to up
 2018-02-18T01:59:08.949257+00:00 heroku[router]: at=info method=GET 
 path="/" host=tyler-dev.herokuapp.com request_id=d19953f5-ab72-4374-
 8bb3-1c391b72912b fwd="74.135.3.158" dyno=web.1 connect=0ms service=41ms 
 status=404 bytes=380 protocol=https




2018-02-18T01:59:08.949562+00:00 app[web.1]: Error: ENOENT: no such file 
 or directory, stat '/Users/tyler/WebDev/portfolio/main/views/index.html'
 2018-02-18T01:59:09.910620+00:00 heroku[router]: at=info method=GET 
 path="/favicon.ico" host=tyler-dev.herokuapp.com request_id=04a7bd40-
 ea40-4806-ba01-b4dd318d41eb fwd="74.135.3.158" dyno=web.1 connect=0ms 
 service=4ms status=404 bytes=394 protocol=https

说丢失的文件不是并且在那个位置。 在本地运行应用程序时,一切正常。 这是我的 node/express 应用程序设置。

app.get('/', function(req, res){
    res.sendFile(path.join(_dirname + '/views/index.html'));
});

app.set('port', (process.env.PORT || 5000));

app.listen(app.get('port'), function(){
    console.log("Server is started!")
});

有没有人遇到过这样的事情?

我是否在 Heroku 中设置了错误?

任何帮助都会很棒,谢谢!

【问题讨论】:

    标签: node.js express heroku


    【解决方案1】:

    这是一篇较旧的帖子,但可能是您需要 path.resolve 而不是 path.join。

    Serving static files from an express/node.js application

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 2019-11-17
      相关资源
      最近更新 更多