我试图在我的openshift服务器上使用socket.io运行我的聊天程序,但每当我尝试重新加载它给我的链接时,它只是继续说:" 503服务错误"。我已经设置了我的存储库正确并使用rhc客户端将我的ssh密钥输入openshift,但无济于事,我使用的是端口3000,我也尝试了端口80,但它们都没有工作。
这是我的服务器代码和我的package.json:
var express = require("express"),
app = express(),
http = require("http").Server(app),
io = require("socket.io")(http),
require("./index.js");
app.use(express.static("static"));
io.on("connection", function(socket) {
console.log("a user connnected");
socket.on("disconnect", function() {
console.log("user disconnected");
});
socket.on("chat message", function(msg) {
console.log("message " + msg);
io.emit("chat message", {m: msg.m, u: msg.u});
});
});
var port;
if(process.argv[2]) {port = process.argv[2]} else {port = 3000}
http.listen(port, function() {
console.log("chat listening on port " + port + ".");
});
我的package.json:
{
"name": "ChatterBox",
"version": "1.0.0",
"description": ".",
"main": "index.js",
"dependencies": {
"express": "^4.12.3",
"socket.io": "^1.3.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/OrganTrouble/ChatterBox.git"
},
"author": "Jesse Davda",
"license": "ISC",
"bugs": {
"url": "https://github.com/OrganTrouble/ChatterBox/issues"
},
"scripts" {
"start": "node $relative_path_from_repo_dir/index.js"
},
"homepage": "https://github.com/OrganTrouble/ChatterBox"
}
答案 0 :(得分:1)
请参阅NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil; // use an NSError if you want
NSArray *scheduleDates = json[@"schedule"];
for (NSDictionary *dates in scheduleDates) {
NSString *endDateString = dates[@"end_date"];
NSString *startDateString = dates[@"start_date"];
}
环境变量(以及页面底部的示例用法):https://developers.openshift.com/en/node-js-environment-variables.html
另请参阅:https://developers.openshift.com/en/node-js-project-structure.html#server.js
答案 1 :(得分:0)
使用$ OPENSHIFT_REPO_DIR代替$ relative_path_from_repo_dir