在尝试打开我的网络应用程序时,Heroku给了我一个503,在本地主机上工作 [英] Heroku is giving me a 503 when trying to open my web app, works on local host

查看:107
本文介绍了在尝试打开我的网络应用程序时,Heroku给了我一个503,在本地主机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署到heroku,但即使它在本地主机上运行,​​也会获得503。我很好奇,如果我的服务器设置正确,因为我更新编程。我希望任何人都可以指出我在正确的方向看哪里或提供建议,因为我已经花了无数小时在谷歌上,跨越了几周的时间。



我的主要问题是如果我正确设置了我的服务器?我不确定我的听众是否会为heroku工作,并且我的.get在初始设置时用于在本地主机上进行调试。



我的完整项目也可以在这里找到:

https://github.com/dirkdir/DerekDevSite

  var express = require('express'); 
var app = express();
var path = require('path');


app.use(express.static(path.join(__ dirname,'public')));

$ b app.get('/ json',function(req,res){
console.log(GET the json);
res
.status(200)
.json({jsonData:true});
});

app.get('/ file',function(req,res){
console.log(GET the file);
res
.status (200)
.sendFile(path.join(__ dirname,'app.js'));
});



var server = app.listen(process.env.PORT || 5000),function(){
var port = server.address()。港口;
console.log(Express正在处理端口+端口);
});

日志:



24T20:04:43.755866 + 00:00 app [web.1]:at Module._compile(module.js:542:28)
2017-04-24T20:04:43.755867 + 00:00 app [web。 1]:在Object.Module._extensions..js(module.js:579:10)
2017-04-24T20:04:43.755868 + 00:00 app [web.1]:at Module.load
2017-04-24T20:04:43.755868 + 00:00 app [web.1]:at tryModuleLoad(module.js:446:12)
2017-04 -24T20:04:43.755869 + 00:00 app [web.1]:在Function.Module._load(module.js:438:3)
2017-04-24T20:04:43.755869 + 00:00 app [web.1]:在Module.runMain(module.js:604:10)
2017-04-24T20:04:43.755870 + 00:00 app [web.1]:在运行时(bootstrap_node.js: 393:7)
2017-04-24T20:04:43.755871 + 00:00 app [web.1]:启动时(bootstrap_node.js:150:9)
2017-04-24T20:04 :43.846556 + 00:00 heroku [web.1]:状态从开始变为崩溃
2017-04-24T20:26:31.826133 + 00:00 heroku [router]:at = error code = H10 desc =应用程序崩溃了method = GET path =/ho st = derekdyerdev.herokuapp.com request_id = 609ef253-0a56-41ac-b877-1fb242f6f4e1 fwd =69.36.89.218dyno = connect = service = status = 503 bytes = protocol = https
2017-04-24T20:26 :32.319732 + 00:00 heroku [router]:at = error code = H10 desc =App crashedmethod = GET path =/ favicon.icohost = derekdyerdev.herokuapp.com request_id = f2a34e62-9765 -

解决方案

您的 <34 $ app.js 文件放在错误的地方。
由于函数是一个回调函数,它必须在参数范围内。



将最后一个块更改为:

  var server = app.listen(process.env.PORT || 5000,function(){
var port = server.address()。
console.log(Express正在处理端口+端口);
});

我也修改了 Procfile

  web:node app.js 

在修改了我能够在本地运行之后,我将它部署到了我的Heroku中,以便测试,并且工作正常:)


I am trying to deploy to heroku but get a 503 even though it runs on localhost. I am curious as to if my server is set up correctly as I am newer to programming. I hope anyone can point me in the correct direction as to where to look or provide a suggestion as I have spent countless hours on google to this point spanning a couple of weeks.

My main question is if I have set up my server correctly? I am not sure my listener will work for heroku and my .get are used for debugging on localhost when it was initially set up.

Also my full project is available here:

https://github.com/dirkdir/DerekDevSite

var express = require('express');
var app = express();
var path = require('path');


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


app.get('/json', function(req, res) {
    console.log("GET the json");
    res
        .status(200)
        .json( {"jsonData" : true} );
});

app.get('/file', function(req, res) {
    console.log("GET the file");
    res
        .status(200)
        .sendFile(path.join(__dirname, 'app.js'));
});



    var server = app.listen(process.env.PORT || 5000), function() {
        var port = server.address().port;
        console.log("Express is working on port " + port);
});

Logs:

2017-04-24T20:04:43.755866+00:00 app[web.1]: at Module._compile (module.js:542:28) 2017-04-24T20:04:43.755867+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10) 2017-04-24T20:04:43.755868+00:00 app[web.1]: at Module.load (module.js:487:32) 2017-04-24T20:04:43.755868+00:00 app[web.1]: at tryModuleLoad (module.js:446:12) 2017-04-24T20:04:43.755869+00:00 app[web.1]: at Function.Module._load (module.js:438:3) 2017-04-24T20:04:43.755869+00:00 app[web.1]: at Module.runMain (module.js:604:10) 2017-04-24T20:04:43.755870+00:00 app[web.1]: at run (bootstrap_node.js:393:7) 2017-04-24T20:04:43.755871+00:00 app[web.1]: at startup (bootstrap_node.js:150:9) 2017-04-24T20:04:43.846556+00:00 heroku[web.1]: State changed from starting to crashed 2017-04-24T20:26:31.826133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=derekdyerdev.herokuapp.com request_id=609ef253-0a56-41ac-b877-1fb242f6f4e1 fwd="69.36.89.218" dyno= connect= service= status=503 bytes= protocol=https 2017-04-24T20:26:32.319732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=derekdyerdev.herokuapp.com request_id=f2a34e62-9765-

解决方案

You have the bracket on line 34 of your app.js file in the wrong place. Since the function is a callback, it needs to be within the params.

Change that last block to this:

var server = app.listen(process.env.PORT || 5000, function () {
  var port = server.address().port;
  console.log("Express is working on port " + port);
});

I also modified the Procfile to just this:

web: node app.js

After I modified that I was able to run locally, and I deployed it to my Heroku just to test, and it works fine :)

这篇关于在尝试打开我的网络应用程序时,Heroku给了我一个503,在本地主机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆