【发布时间】:2016-03-17 01:07:05
【问题描述】:
我正在尝试为学校项目创建 NodeJS 应用程序。基本思想是一个 NodeJS 服务器,它将处理对它的请求并跟踪具有特定格式的请求(这些将来自发布在各个区域的 QR 码)。
我想使用 OpenShift 来托管应用程序,并且可以构建它,但每次我发布 URL 时都会出现 503 错误,即使我使用格式正确的请求(例如:psychexpserver-psychexp .rhcloud.com/MU-EllisLib-Blue-NoPhrase)。我已经在本地测试了该应用程序,它运行良好。我已经研究了该主题,但没有找到适合我的答案 端口是否配置错误?我应该转到其他网址吗?
代码:
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);
});
谢谢!
编辑:大家好,感谢大家的回答和建议。不幸的是,问题仍然存在(至少对我而言),并且由于时间限制,我不得不寻找不同的托管服务。不过,我仍然会检查这个问题,看看我们是否能解决这个问题!再次感谢!
【问题讨论】:
-
您是否尝试过 SSH 进入您的应用 (
rhc ssh psychexpserver) 并检查~/app-root/logs/nodejs.log? -
是的,最新的日志消息显示没有错误。
标签: javascript node.js openshift