OpenShift NodeJS 应用程序 503 错误(端口问题?
OpenShift NodeJS Application 503 Error (port issue?)
我正在尝试为学校项目创建一个 NodeJS 应用程序。基本思想是一个 NodeJS 服务器,它将处理对它的请求并跟踪特定格式的请求(这些将来自各个区域发布的二维码)。
我想使用 OpenShift 来托管应用程序,并且我让它构建正常,但是每次我发布 URL 时,即使我使用格式正确的请求(例如:psychexpserver-psychexp.rhcloud.com/MU-EllisLib-Blue-NoPhrase),它也会给我一个 503 错误。我已经在本地测试了该应用程序,它工作正常。我已经研究了这个主题,但我没有找到适合我的答案 端口配置错误吗?我应该转到其他网址吗?
法典:
var app = require('express')();
var http = require('http').Server(app);
var fs = require('fs');
// Port which we listen to - get from OpenShift
var serverPort = process.env.OPENSHIFT_NODEJS_PORT || 80;
var serverIp = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
app.set('port', serverPort);
app.set('ipaddr', serverIp);
// Data logging
app.get('/:val', function(req, res)
{
// Grab request url
var data = req.url;
// Process and write to file
processData(data);
// Redirect to follow up form
res.redirect('https://docs.google.com/forms/d/11JbF4FE_Vd1Dd6PD8wMbs4Kxc15GgA3NL6vDGYEjtZY/viewform?c=0&w=1');
});
function processData(data)
{
// Get timestamp
var now = new Date();
// Set time zone
now.setHours(now.getHours() - 6);
var timestamp = now.toUTCString();
// Parse request
var info = timestamp + ";_";
// Sample communities and areas
if(data.includes("RB"))
{
info += 'RB;_';
// Sample area
if(data.includes("North"))
info += 'North Coms;_';
else if(data.includes("Main"))
info += 'Main Coms;_';
else if(data.includes("Atrium"))
info += 'Atrium;_';
}
else if(data.includes("MU"))
{
info += 'MU;_';
// Sample area
if(data.includes("Strickland"))
info += 'Strick;_';
else if(data.includes("EllisLib"))
info += 'EllisLib;_';
else if(data.includes("Engineering"))
info += 'Engineer;_';
}
else if(data.includes("DT"))
{
info += 'DT;_';
// Sample area
if(data.includes("North"))
info += 'North;_';
else if(data.includes("West"))
info += 'West;_';
else if(data.includes("East"))
info += 'East;_';
else if(data.includes("South"))
info += 'South;_';
}
// Oh no, something's wrong
else
{
info += 'Invalid Access;_';
}
// Color
if(data.includes("Red"))
info += 'Red;_';
else if(data.includes("Blue"))
info += 'Blue;_';
else if(data.includes("Yellow"))
info += 'Yellow;_';
else if(data.includes("Blank"))
info += 'Blank;_';
// Phrase?
if(data.includes("Phrase"))
info += 'Phrase;';
else if(data.includes("NoPhrase"))
info += 'NoPhrase;';
// Terminate line
info += '__'t';
// Log
console.log('Got: ' + info);
// Log into file
fs.appendFileSync("data.txt", info, 'utf8');
}
http.listen(serverPort, serverIp,
function()
{
console.log("Listening on: " + serverIp + ":" + serverPort);
});
谢谢!
编辑:嘿伙计们,感谢大家的回答和建议。不幸的是,问题仍然存在(至少对我来说),由于时间限制,我不得不寻找不同的托管服务。不过,我仍然会检查这个问题,看看我们是否可以解决这个问题!再次感谢!
您似乎正在尝试使用express
和http
服务器,而且它有点混合。此外,您希望 String 对象具有includes
函数并存储您的data.txt
,这样它就不会在 OpenShift Online 上的 git 推送中幸存下来。我对你的server.js
代码做了一些小的编辑:
-
使用快递:
var express = require('express'); var app = express(); var fs = require('fs');
对 includes
方法进行原型设计:String.prototype.includes = function(substr) { return this.indexOf(substr) != -1; }
听快递:
app.listen(serverPort, serverIp,
您还希望最有可能将
data.txt
放在OPENSHIFT_DATA_DIR
中,以免每次推送 git 时都擦除它,但我在这里没有做任何更改。查看有关 OpenShift 上的持久数据存储的更多详细信息。
所以现在我有以下内容,它似乎正在 OpenShift 的 nodejs 墨盒上工作(我的意思是它会记录内容、进行重定向并将data.txt
存储在 ~/app-root/runtime/repo/
中):
var express = require('express');
var app = express();
var fs = require('fs');
// Port which we listen to - get from OpenShift
var serverPort = process.env.OPENSHIFT_NODEJS_PORT || 80;
var serverIp = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
// Data logging
app.get('/:val', function(req, res)
{
// Grab request url
var data = req.url;
// Process and write to file
processData(data);
// Redirect to follow up form
res.redirect('http://goo.gl/forms/VGU9K99735');
});
function processData(data)
{
// Get timestamp
var now = new Date();
// Set time zone
now.setHours(now.getHours() - 6);
var timestamp = now.toUTCString();
// Parse request
var info = timestamp + ";_";
// seems like you want "includes" method for string objects
String.prototype.includes = function(substr)
{
return this.indexOf(substr) != -1;
}
// Sample communities and areas
if(data.includes("RB"))
{
info += 'RB;_';
// Sample area
if(data.includes("North"))
info += 'North Coms;_';
else if(data.includes("Main"))
info += 'Main Coms;_';
else if(data.includes("Atrium"))
info += 'Atrium;_';
}
else if(data.includes("MU"))
{
info += 'MU;_';
// Sample area
if(data.includes("Strickland"))
info += 'Strick;_';
else if(data.includes("EllisLib"))
info += 'EllisLib;_';
else if(data.includes("Engineering"))
info += 'Engineer;_';
}
else if(data.includes("DT"))
{
info += 'DT;_';
// Sample area
if(data.includes("North"))
info += 'North;_';
else if(data.includes("West"))
info += 'West;_';
else if(data.includes("East"))
info += 'East;_';
else if(data.includes("South"))
info += 'South;_';
}
// Oh no, something's wrong
else
{
info += 'Invalid Access;_';
}
// Color
if(data.includes("Red"))
info += 'Red;_';
else if(data.includes("Blue"))
info += 'Blue;_';
else if(data.includes("Yellow"))
info += 'Yellow;_';
else if(data.includes("Blank"))
info += 'Blank;_';
// Phrase?
if(data.includes("Phrase"))
info += 'Phrase;';
else if(data.includes("NoPhrase"))
info += 'NoPhrase;';
// Terminate line
info += '__'t';
// Log
console.log('Got: ' + info);
// Log into file
fs.appendFileSync("data.txt", info, 'utf8');
}
app.listen(serverPort, serverIp,
function()
{
console.log("Listening on: " + serverIp + ":" + serverPort);
});
//EOF
- 我该如何解决这个问题?“未捕获的类型错误:无法读取 null 的属性'appendChild'”
- 遇到400错误请求(Angular+WebAPI)的问题
- 扩展错误es6类模块问题
- Createjs冲突问题localToLocal不是函数错误
- Ckeditor出现格式错误的html问题
- 用Javascript为QCM动态生成问题——未捕获类型错误
- 访问模板中的属性时出现问题-除'name'显示错误'没有定义[attributename];
- Meteor上有错误的同步问题
- AJAX自定义错误处理代码问题
- Javascript在每个有问题的控件上输出一条错误消息
- 未捕获的语法错误:意外的令牌:跨域问题
- 我在帖子#index中得到以下错误ExecJS::ProgramError我该如何修复此问题
- 防止在php中缓存500内部错误页面的问题
- 代码有什么问题?它给了我一个运行时错误
- NaN 错误代码有什么问题
- Firefox SDK:包括jquery.flot在内的问题,错误显示维度高度为空
- 这个代码出了什么问题?错误丢失”)&”;
- Javascript变量作用域问题-错误:类型错误:this.graphics未定义
- jQuery修复了" Uncaught TypeError: $不是一个函数"的问题错误
- 解决在angular模板中包含脚本标签导致“同步XMLHttpRequest..”的问题;错误感觉很脏