simplify server

pull/1/head
ansuz 7 years ago
parent f96a5003b0
commit 5b84bc1a25

@ -10,13 +10,14 @@ try {
} }
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/'; var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
module.exports.install = function(server, callbackFunction) { module.exports.install = function(server, port, callbackFunction) {
console.log();
var sockjs_opts = {sockjs_url: ""}, var sockjs_opts = {sockjs_url: ""},
sockjs_echo = sockjs.createServer(sockjs_opts); sockjs_echo = sockjs.createServer(sockjs_opts);
//urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i'); //urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
console.log("Start ooserver"); console.log("Start ooserver");
console.log("Port " + sockjs_echo.port); console.log("Port " + port);
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) { function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
var url = ''; var url = '';
@ -64,9 +65,10 @@ module.exports.install = function(server, callbackFunction) {
try { try {
console.log("Received: " + message); console.log("Received: " + message);
data = JSON.parse(message); data = JSON.parse(message);
switch (data.type) {
case 'auth': if (data.type !== 'auth') { return; }
console.log("Response auth"); console.log("Response auth");
var fileUrl = origin + "oodoc/test.bin"; var fileUrl = origin + "oodoc/test.bin";
if (data.openCmd) { if (data.openCmd) {
@ -78,10 +80,6 @@ module.exports.install = function(server, callbackFunction) {
} }
sendData(conn, {"type":"auth","result":1,"sessionId":"08e77705-dc5c-477d-b73a-b1a7cbca1e9b","sessionTimeConnect":1494226099270,"participants":[]}); sendData(conn, {"type":"auth","result":1,"sessionId":"08e77705-dc5c-477d-b73a-b1a7cbca1e9b","sessionTimeConnect":1494226099270,"participants":[]});
sendData(conn, {"type":"documentOpen","data":{"type":"open","status":"ok","data":{"Editor.bin":fileUrl}}}); sendData(conn, {"type":"documentOpen","data":{"type":"open","status":"ok","data":{"Editor.bin":fileUrl}}});
break;
default:
break;
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
//console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack); //console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack);

@ -251,7 +251,7 @@ app.use(function (req, res, next) {
var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app);
/* Install sockjs websocket server */ /* Install sockjs websocket server */
OOServer.install(httpServer, () => { OOServer.install(httpServer, config.httpPort, () => {
httpServer.listen(config.httpPort,config.httpAddress,function(){ httpServer.listen(config.httpPort,config.httpAddress,function(){
var host = config.httpAddress; var host = config.httpAddress;
var hostName = !host.indexOf(':') ? '[' + host + ']' : host; var hostName = !host.indexOf(':') ? '[' + host + ']' : host;
@ -264,7 +264,7 @@ OOServer.install(httpServer, () => {
}); });
if (config.httpSafePort) { if (config.httpSafePort) {
var safeHttpServer = Http.createServer(app).listen(config.httpSafePort, config.httpAddress); var safeHttpServer = Http.createServer(app).listen(config.httpSafePort, config.httpAddress);
OOServer.install(safeHttpServer, () => { OOServer.install(safeHttpServer, config.httpSafePort, () => {
}); });
} }

Loading…
Cancel
Save