【问题标题】:How to deploy node app on openshift and run it?如何在 openshift 上部署节点应用程序并运行它?
【发布时间】:2017-12-07 19:36:28
【问题描述】:

刚刚使用 node 创建了一个非常简单的 hello world 应用程序:

var express = require('express');
var app = express();
app.get('/', function (req, res) {
  res.send('Hello World!');
});
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'

app.listen(server_port, server_ip_address, function () {
  console.log( "Listening on " + server_ip_address + ", port " + server_port )
});

它在我的本地机器上按预期工作,

把它放在 github 上并将其部署在 openshift 上,创建 pod 并且服务器运行良好: 但是当我浏览 the route 时,我可以在 Application>>routes 菜单中找到它:

Application is not available

The application is currently not serving requests at this endpoint. It may not have been started or is still starting.
I guess I'm using the latest version of openshift since just created an account.

我期待它向我展示 Hello 世界!

更新1:

这是我的 package.json:

{
  "name": "npmtest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.2"
  }
}

【问题讨论】:

    标签: node.js deployment openshift


    【解决方案1】:

    您的应用服务器 IP 地址必须是 0.0.0.0。因此,您要么为此指定一个环境变量,要么对其进行硬编码。

    【讨论】:

    • 我把ip换成了0.0.0.0但是还是不行
    • 哦,实际上 1 分钟后它与 0.0.0.0 ip 一起工作!谢谢!
    【解决方案2】:

    你有没有在 package.json 中配置主文件

    也许您需要从环境变量中动态获取端口,请查看以下链接以获取 openshift 示例

    https://github.com/openshift/nodejs-ex

    【讨论】:

    • 是的,我编辑了我的帖子并包含了 package.json,它配置了 main。我相信我正在使用这一行动态设置 IP: var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
    猜你喜欢
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    相关资源
    最近更新 更多