0
您可以在下面的代碼中看到它們是兩個端口(port1和port2)。它在舊的OpenShift(v2)上運行良好,但我無法在新版本3.5上運行。我如何在新版本上運行此代碼。 端口1 - 這是使用的WebSocket, 端口2 - 這是使用HTTP POST請求 來源:https://github.com/hayageek/WhatsApp-Web如何在Openshift上打開兩個端口3.5
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
var ip = process.env.OPENSHIFT_NODEJS_IP;
var port1 = 8080;
var port2 = 8081;
var WebSocketServer = require('ws').Server
var uuid = require('node-uuid');
var wss = new WebSocketServer({ path:'/gencode',port: port1,server:ip });
var clients = {};
var dumCounter=0;
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
var obj = JSON.parse(message);
if(obj.op == 'hello')
{
var uuidToken = uuid.v1();
clients[uuidToken] = ws;
var hello = { op:'hello',token:uuidToken};
ws.send(JSON.stringify(hello),{mask:false});
}
});
});
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain","Access-Control-Allow-Origin":"*"});
process.on('uncaughtException', function(err) {
response.end("Exception");
});
if(request.method == "POST")
{
var url = request.url;
if(url == "/auth")
{
var body = '';
request.on('data', function(chunk)
{
body += chunk.toString();
});
request.on('end', function() {
var params = JSON.parse(body);
console.log("Recived Params: "+JSON.stringify(params));
var uuId = params.uuid;
var accessToken = params.access_token;
var msg = {'op':'authdone','accessToken':accessToken};
if(clients[uuId] != undefined || clients[uuId] != null)
{
console.log("Before "+Object.size(clients));
clients[uuId].send(JSON.stringify(msg),{mask:false});
delete clients[uuId];
console.log("After "+Object.size(clients));
response.end('{"status":"OK"}');
}
else
{
response.end('{"status":"NOK"}');
}
});
}
else
{
response.end('{"status":"NOK"}');
}
}
else
{
response.end("NOT Supported");
}
}).listen(port2,ip);
我真的很抱歉我在OpenShift新的,所以我沒有任何想法關於在部署配置和服務中進行編輯。你能幫我嗎? –
我會嘗試你告訴我的任何事情,但沒有任何事情發生。 **規格: 端口: - 名稱:8080-TCP 協議:TCP端口 :8080 TARGETPORT:8080 - 名稱:8081-HTTP 協議:TCP端口 :8081 TARGETPORT:8081 ** –
如果是您正在使用'oc'命令行工具,然後在項目中運行'oc get dc'和'oc edit dc XYZ',其中XYZ是要編輯的應用程序的部署配置名稱。然後用'oc get svc'來編輯服務。它看起來像你可能已經編輯的路線已經 – user2983542