GVKun编程网logo

Node.js:简单的应用程序无法在Heroku上运行(node应用程序错误)

10

对于想了解Node.js:简单的应用程序无法在Heroku上运行的读者,本文将提供新的信息,我们将详细介绍node应用程序错误,并且为您提供关于Heroku上的HTTPSNode.js应用程序、jav

对于想了解Node.js:简单的应用程序无法在Heroku上运行的读者,本文将提供新的信息,我们将详细介绍node应用程序错误,并且为您提供关于Heroku上的HTTPS Node.js应用程序、java – 在Heroku上运行Dropwizard应用程序:R10无法绑定到$PORT、javascript – Heroku在heroku上找不到本地模块(Node.js)、node.js – 为什么我的应用程序不能在Heroku上建立websocket连接?的有价值信息。

本文目录一览:

Node.js:简单的应用程序无法在Heroku上运行(node应用程序错误)

Node.js:简单的应用程序无法在Heroku上运行(node应用程序错误)

我已经编写了一个基本的node.js应用程序,并且设法将其部署在Heroku上没有任何问题。我创建了 package.json
Procfile ,但是从日志中看到没有正在运行的进程,因此无法获得任何响应。可能是什么问题呢?

PS: 我不想使用 Express 框架

我的代码:

var http = require("http");http.createServer(function(request, response) {  response.writeHead(200, {"Content-Type": "text/plain"});  response.write("Hello World");  response.end();  console.log("I am working");}).listen(8888);

我的package.json:

{  "name": "node-example",  "version": "0.0.1",  "dependencies": {  },  "engines": {    "node": "0.8.x",    "npm": "1.1.x"  }}

日志:

2012-10-22T12:36:58+00:00 heroku[slugc]: Slug compilation started2012-10-22T12:37:07+00:00 heroku[slugc]: Slug compilation finished2012-10-22T12:40:55+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=2012-10-22T12:50:44+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=

答案1

小编典典

您已缩放heroku应用程序了吗?

$ heroku ps:scale web=1

这是必需的步骤。该1是你想催生了您的应用程序的进程数。

Heroku上的HTTPS Node.js应用程序

Heroku上的HTTPS Node.js应用程序

我已经配置了SSL enpoint,并且可以确认它正在工作。当我进入日志时,会看到以下内容:

Jul 13 08:14:10 support-dash app/web.1:  Express server listening on port 17621 Jul 13 08:14:10 support-dash heroku/web.1:  Stopping all processes with SIGTERM Jul 13 08:14:11 support-dash heroku/web.1:  State changed from starting to up Jul 13 08:14:13 support-dash heroku/web.1:  Process exited with status 143 Jul 13 08:15:48 support-dash heroku/router:  at=error code=H12 desc="Request timeout" method=GET path=/ host=app.supportdash.com fwd="68.63.87.85" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 Jul 13 08:16:18 support-dash heroku/router:  at=error code=H12 desc="Request timeout" method=GET path=/favicon.ico host=app.supportdash.com fwd="68.63.87.85" dyno=web.1 connect=2ms service=30007ms status=503 bytes=0

我试图追踪有关退出代码143的一些信息,以及为什么所有进程都被停止。签出以下服务器文件:

var http = require(''http'');var https = require(''https'');var fs = require(''fs'');var express = require("express");var app = express();app.set(''port'', process.env.PORT || 3000);app.use(express.logger());app.get(''/'', function(request, response) {  response.send(''Hello World 2!'');});var privateKey = fs.readFileSync(__dirname + ''/ssl/server.key'').toString();var certificate = fs.readFileSync(__dirname + ''/ssl/gandiSSL.pem'').toString();var options = {  key: privateKey,  cert: certificate};https.createServer(options, app).listen(process.env.PORT, function () {  console.log("Express server listening on port " + app.get(''port''));});

感谢您的提前反馈。如果需要,我可以提供更多详细信息。

------解决方案(编辑)-------

请参阅下面的答案。

答案1

小编典典

我在这里找到了答案:ExpressJS节点HTTPS服务器上的Heroku错误H13

“ SSL终止发生在Heroku的负载均衡器上;它们会向您的应用发送普通(非SSL)流量,因此您的应用应创建一个非HTTPS服务器。”

然后,我将文件更改为:

var http = require(''http'');var express = require("express");var app = express();app.set(''port'', process.env.PORT || 3000);app.use(express.logger());app.get(''/'', function(request, response) {  console.log(''[support dash] processing get request'')  response.send(''Hello World 2!'');});app.listen(process.env.PORT, function () {  console.log(''***** exp listening on port: '' + process.env.PORT);});

现在一切都通过https运行良好。祝好运!

java – 在Heroku上运行Dropwizard应用程序:R10无法绑定到$PORT

java – 在Heroku上运行Dropwizard应用程序:R10无法绑定到$PORT

我最近指出了dropwizard和heroku的方向,以便相对容易地创建和部署restFUL web服务.

在http://dropwizard.readthedocs.org/en/latest/getting-started.html开始学习入门教程之后,我很快就在我的localhost上运行了一个简单的Hello World服务,没有任何问题.

继续试图在Heroku上部署它我遇到了一个问题.在将应用程序部署到heroku时,我收到错误消息

2014-08-14T11:34:59.869067+00:00 heroku[web.1]: State changed from starting to crashed
2014-08-14T11:34:59.070364+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process Failed to bind to $PORT within 60 seconds of launch
2014-08-14T11:34:59.070573+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-08-14T11:34:59.857478+00:00 heroku[web.1]: Process exited with status 137

我的procfile看起来像….

web java $JAVA_OPTS -D.http.port=$PORT -jar target/exampleMavenProject-0.0.1-SNAPSHOT.jar server hello-world.yml

这与在本地主机上运行应用程序的命令行代码完全相同,但不包括

$JAVA_OPTS -D.http.port=$PORT

$jAVA_OPTS在herkou app配置变量中定义;从我的理解,$PORT不能被覆盖.

除了dropwizard示例所需的那些之外,hello-world.yml中没有任何额外的配置变量

template: Hello,%s!

defaultName: Stranger

有没有人有任何建议,为什么这不起作用?

谢谢.

解决方法

Dropwizard 0.7.x改变了他们的服务器配置;特别是,http.port不再起作用了.

相反,您应该使用server.connector.port作为procfile / .yml文件.这是一个例子:

procfile

web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -jar target/pos-tagger-1.0-SNAPSHOT.jar server src/main/resources/POSTagger.yml

POSTagger.yml

server:
  type: simple
  applicationcontextpath: /
  admincontextpath: /admin
  connector:
    type: http
    port: 8080

如果你想看到一个完整的,使用0.7.x的heroku示例,请查看:https://github.com/xinranxiao/POSTagger

javascript – Heroku在heroku上找不到本地模块(Node.js)

javascript – Heroku在heroku上找不到本地模块(Node.js)

我正在开发一个Node.js应用程序,并且正在使用一个公开我的twitter API令牌/秘密的config.js文件.我这样做是因为我计划在完成应用程序之后开源应用程序,并且希望将这些应用程序保密(因此,将该文件放在我的.gitignore中).

无论如何,对我的问题 – 我收到以下错误日志:

2012-04-09T22:41:12+00:00 app[web.1]: node.js:134
2012-04-09T22:41:12+00:00 app[web.1]:         ^
2012-04-09T22:41:12+00:00 app[web.1]:         throw e; // process.nextTick error,or 'error' event on first tick
2012-04-09T22:41:12+00:00 app[web.1]: Error: Cannot find module './config'
2012-04-09T22:41:12+00:00 app[web.1]:     at require (module.js:348:19)
2012-04-09T22:41:12+00:00 app[web.1]:     at Function._load (module.js:266:25)
2012-04-09T22:41:12+00:00 app[web.1]:     at Function._resolveFilename (module.js:320:11)
2012-04-09T22:41:12+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:6:19)
2012-04-09T22:41:12+00:00 app[web.1]:     at Module._compile (module.js:404:26)
2012-04-09T22:41:12+00:00 app[web.1]:     at Object..js (module.js:410:10)
2012-04-09T22:41:12+00:00 app[web.1]:     at Function._load (module.js:297:12)
2012-04-09T22:41:12+00:00 app[web.1]:     at EventEmitter._tickCallback (node.js:126:26)
2012-04-09T22:41:12+00:00 app[web.1]:     at Module.load (module.js:336:31)
2012-04-09T22:41:12+00:00 app[web.1]:     at Array.<anonymous> (module.js:423:10)
2012-04-09T22:41:13+00:00 heroku[web.1]: State changed from starting to crashed
2012-04-09T22:41:13+00:00 heroku[web.1]: Process exited with status 1

我的文件名是config.js,我在我的应用程序中执行:var config = require(‘./ config’).我没有将它列为我的package.json文件中的依赖项,因为它不在NPM中.

在本地与工头和procfile一起运行(就像heroku的文档说的那样)工作得很好.但是,当我需要一个本地文件时,我很困惑为什么它会给我一个错误. config.js与我的app.js位于同一目录级别,因此要求它的路径是正确的.

编辑:下面是我在app.js中使用的代码部分:

var express     = require('express'),sys         = require('sys'),request     = require('request'),config      = require('./config')

谢谢 – 任何帮助将不胜感激!

解决方法

因为你把config.js文件放在.gitignore中,所以它没有像你说的那样被推送到Heroku服务器.对于您想要做的事情,您通常会使用 Heroku’s config vars设置环境变量,然后由应用程序读入:
$heroku config:add TWITTER_TOKEN=<token> TWITTER_SECRET=<secret>

然后在app.js文件中,您可以使用以下命令访问这些环境变量:

var token = process.env['TWITTER_TOKEN'];
var secret = process.env['TWITTER_SECRET'];

node.js – 为什么我的应用程序不能在Heroku上建立websocket连接?

node.js – 为什么我的应用程序不能在Heroku上建立websocket连接?

我正在尝试在heroku上部署我的nodejs应用程序.我无法建立websocket连接.我已经阅读了我能找到的所有内容,尝试了每一个例子,但似乎没有一个适合我.

当我尝试打开我的页面“heroku open”时,nodejs正确地给了我html文件.然而,websocket’ws’连接永远不会建立.

我的server.js有以下配置:

var pport = process.env.PORT || 5000;
server.listen(pport,function(err) {
    if(!err) { console.log("Listening on port " + pport); }
});

边注
当我检查“heroku日志”时,我发现我的应用程序运行的端口是一个随机的5位数字. (如28896,53365等)它实际上从未在下半场运行|| 5000.

但问题是,为了让我的game.html文件建立一个websocket连接,它需要知道什么端口.
我尝试了以下客户端配置,没有一个工作:

1)

var host = location.origin.replace(/^http/,'ws');
this.connection = new WebSocket(host);

2)

var host = location.origin.replace(/^http/,'ws');
host = host + ":5000";
this.connection = new WebSocket(host);

3)

this.connection = new WebSocket('ws://infinite-earth-7708.herokuapp.com/');

我也完成了他们网站所说的内容,并在部署我的应用后尝试使用以下内容:

heroku config:add NODE_ENV=production

请指教

解决方法

好吧我明白了.这是你应该知道的:

>我没有从原始帖子更改我的服务器配置.

我的客户端配置如下所示:

var host = location.origin.replace(/^http/,'ws');
this.connection = new WebSocket(host);

但这里是踢球者.
在终端上我使用了以下命令:

heroku labs:enable websockets

瞧,它有效!我希望这可以帮助别人.

关于Node.js:简单的应用程序无法在Heroku上运行node应用程序错误的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Heroku上的HTTPS Node.js应用程序、java – 在Heroku上运行Dropwizard应用程序:R10无法绑定到$PORT、javascript – Heroku在heroku上找不到本地模块(Node.js)、node.js – 为什么我的应用程序不能在Heroku上建立websocket连接?等相关知识的信息别忘了在本站进行查找喔。

本文标签: