【问题标题】:Get request in openshift node js app在 openshift 节点 js 应用程序中获取请求
【发布时间】:2016-05-18 11:00:55
【问题描述】:

我正在构建一个必须与 youtube 数据 API 通信的 openshift 节点 js 应用程序。当我对 require 进行“git push”时,它的部署是成功的。

    /*
    var request = require('request');
    */

当我取消注释时,我收到此错误:

remote: Waiting for application port (8080) become available ...
remote: Application 'eln' failed to start (port 8080 not available)
remote: -------------------------
remote: Git Post-Receive Result: failure
remote: Activation status: failure
remote: Activation failed for the following gears:
remote: 573c3e177628e146d400004e (Error activating gear: CLIENT_ERROR: Failed to execute: 'control start' for /var/lib/openshift/573c3e177628e146d400004e/nodejs

我做得不好吗?我该如何解决?

谢谢。

编辑1:添加监听代码,我没有修改(我创建应用时已经在这里)。

    self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
    self.port      = process.env.OPENSHIFT_NODEJS_PORT || 8080;

    /**
     *  Start the server (starts up the sample application).
     */
    self.start = function()
    {
        //  Start the app on the specific interface (and port).
        self.app.listen(self.port, self.ipaddress, function()
        {
            console.log('%s: Node server started on %s:%d ...', Date(Date.now() ), self.ipaddress, self.port);
        });
    };

【问题讨论】:

  • 您的应用程序是否在侦听任何端口?如果是,那么请告诉我您的监听方法代码
  • 在帖子中添加。

标签: javascript node.js openshift


【解决方案1】:

这是我的 app.js 在 openshift 上工作的基本代码。

#!/bin/env node

ipaddress = process.env.OPENSHIFT_NODEJS_IP;

if (typeof ipaddress === "undefined") {
    //  Log errors on OpenShift but continue w/ 127.0.0.1 - this
    //  allows us to run/test the app locally.
    console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
    ipaddress = "127.0.0.1";
};

var server = app.listen(8080, ipaddress, function() {
  console.log('Listening on port %d', server.address().port);
});

你可以试试吗?

更新

在使用 request 在 openshift 上尝试后,我也遇到了这个错误,但这是因为 package.json 在依赖项下没有 request

我的依赖项现在看起来像这样,并且工作正常:

  "dependencies": {
    "ejs": "^2.4.1",
    "express": "~3.4.4",
    "request": "latest" // this is added
  },

【讨论】:

  • 它有效。但是一旦我添加了我需要的需求(var request = require('request')),由于这个端口问题,它无法部署。
  • 我在本地尝试过请求,它工作正常,您在本地尝试过吗?稍后我会在 openshift 上尝试一下,如果我遇到同样的错误,请告诉您。
  • 我的代码在本地运行良好,但在 openshift 上部署时无法运行。
猜你喜欢
  • 2015-09-15
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
  • 2019-06-17
  • 2019-12-15
  • 2016-04-18
  • 2016-07-31
相关资源
最近更新 更多