2011-03-26 15:52:56 +01:00
|
|
|
/**
|
2011-05-30 16:53:11 +02:00
|
|
|
* This module is started with bin/run.sh. It sets up a Express HTTP and a Socket.IO Server.
|
|
|
|
* Static file Requests are answered directly from this module, Socket.IO messages are passed
|
|
|
|
* to MessageHandler and minfied requests are passed to minified.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-08-11 16:26:41 +02:00
|
|
|
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
|
2011-03-26 15:52:56 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2011-12-04 16:50:02 +01:00
|
|
|
var ERR = require("async-stacktrace");
|
2011-08-03 20:31:25 +02:00
|
|
|
var log4js = require('log4js');
|
2011-08-18 22:29:34 +02:00
|
|
|
var os = require("os");
|
2011-05-28 19:09:17 +02:00
|
|
|
var socketio = require('socket.io');
|
2011-06-30 21:03:09 +02:00
|
|
|
var fs = require('fs');
|
2011-07-27 19:52:23 +02:00
|
|
|
var settings = require('./utils/Settings');
|
|
|
|
var db = require('./db/DB');
|
2011-05-19 18:36:26 +02:00
|
|
|
var async = require('async');
|
|
|
|
var express = require('express');
|
|
|
|
var path = require('path');
|
2011-07-27 19:52:23 +02:00
|
|
|
var minify = require('./utils/Minify');
|
2011-07-25 17:31:41 +02:00
|
|
|
var formidable = require('formidable');
|
2012-02-24 17:59:14 +01:00
|
|
|
var plugins = require("./pluginfw/plugins");
|
|
|
|
var hooks = require("./pluginfw/hooks");
|
2011-08-03 20:31:25 +02:00
|
|
|
var apiHandler;
|
2011-07-19 20:48:11 +02:00
|
|
|
var exportHandler;
|
2011-07-21 21:13:58 +02:00
|
|
|
var importHandler;
|
2011-07-08 19:33:01 +02:00
|
|
|
var exporthtml;
|
|
|
|
var readOnlyManager;
|
2011-08-04 17:07:58 +02:00
|
|
|
var padManager;
|
2011-08-15 23:20:37 +02:00
|
|
|
var securityManager;
|
2011-08-16 16:53:09 +02:00
|
|
|
var socketIORouter;
|
2011-05-19 18:36:26 +02:00
|
|
|
|
2011-06-30 21:03:09 +02:00
|
|
|
//try to get the git version
|
|
|
|
var version = "";
|
|
|
|
try
|
|
|
|
{
|
2012-01-05 11:35:40 +01:00
|
|
|
var rootPath = path.normalize(__dirname + "/../")
|
|
|
|
var ref = fs.readFileSync(rootPath + ".git/HEAD", "utf-8");
|
|
|
|
var refPath = rootPath + ".git/" + ref.substring(5, ref.indexOf("\n"));
|
2011-06-30 21:03:09 +02:00
|
|
|
version = fs.readFileSync(refPath, "utf-8");
|
2011-08-19 23:01:33 +02:00
|
|
|
version = version.substring(0, 7);
|
|
|
|
console.log("Your Etherpad Lite git version is " + version);
|
2011-06-30 21:03:09 +02:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2011-07-31 19:25:51 +02:00
|
|
|
console.warn("Can't get git version for server header\n" + e.message)
|
2011-06-30 21:03:09 +02:00
|
|
|
}
|
|
|
|
|
2011-08-21 20:52:24 +02:00
|
|
|
console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues")
|
|
|
|
|
2011-06-30 21:03:09 +02:00
|
|
|
var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";
|
|
|
|
|
2011-07-21 21:13:58 +02:00
|
|
|
//cache 6 hours
|
2011-06-30 13:43:11 +02:00
|
|
|
exports.maxAge = 1000*60*60*6;
|
2011-05-19 18:36:26 +02:00
|
|
|
|
2011-08-17 18:45:47 +02:00
|
|
|
//set loglevel
|
|
|
|
log4js.setGlobalLogLevel(settings.loglevel);
|
|
|
|
|
2011-05-14 19:57:07 +02:00
|
|
|
async.waterfall([
|
2012-02-24 23:38:37 +01:00
|
|
|
//initalize the database
|
|
|
|
function (callback)
|
|
|
|
{
|
|
|
|
db.init(callback);
|
|
|
|
},
|
|
|
|
|
2012-02-24 17:59:14 +01:00
|
|
|
plugins.update,
|
|
|
|
|
2012-02-24 20:45:02 +01:00
|
|
|
function (callback) {
|
2012-02-25 15:44:04 +01:00
|
|
|
console.log("Installed plugins: " + plugins.formatPlugins());
|
|
|
|
console.log("Installed parts:\n" + plugins.formatParts());
|
|
|
|
console.log("Installed hooks:\n" + plugins.formatHooks());
|
2012-02-24 20:45:02 +01:00
|
|
|
callback();
|
|
|
|
},
|
|
|
|
|
2011-05-19 18:36:26 +02:00
|
|
|
//initalize the http server
|
2011-05-14 19:57:07 +02:00
|
|
|
function (callback)
|
2011-03-26 14:10:41 +01:00
|
|
|
{
|
2011-05-19 18:36:26 +02:00
|
|
|
//create server
|
|
|
|
var app = express.createServer();
|
2012-02-25 13:38:09 +01:00
|
|
|
hooks.callAll("expressCreateServer", {"app": app});
|
2012-02-24 17:59:14 +01:00
|
|
|
|
2012-01-17 10:42:06 +01:00
|
|
|
app.use(function (req, res, next) {
|
|
|
|
res.header("Server", serverName);
|
|
|
|
next();
|
|
|
|
});
|
2011-07-08 19:33:01 +02:00
|
|
|
|
2012-02-25 13:38:09 +01:00
|
|
|
app.configure(function() { hooks.callAll("expressConfigure", {"app": app}); });
|
2011-05-19 18:36:26 +02:00
|
|
|
|
|
|
|
//let the server listen
|
2011-07-30 17:39:53 +02:00
|
|
|
app.listen(settings.port, settings.ip);
|
|
|
|
console.log("Server is listening at " + settings.ip + ":" + settings.port);
|
2011-05-14 19:57:07 +02:00
|
|
|
|
2012-02-25 16:24:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-19 18:36:26 +02:00
|
|
|
//init socket.io and redirect all requests to the MessageHandler
|
|
|
|
var io = socketio.listen(app);
|
2011-06-20 12:44:04 +02:00
|
|
|
|
2011-07-05 19:26:31 +02:00
|
|
|
//this is only a workaround to ensure it works with all browers behind a proxy
|
|
|
|
//we should remove this when the new socket.io version is more stable
|
2011-11-25 19:39:33 +01:00
|
|
|
io.set('transports', ['xhr-polling']);
|
2011-07-05 19:26:31 +02:00
|
|
|
|
2011-07-31 19:25:51 +02:00
|
|
|
var socketIOLogger = log4js.getLogger("socket.io");
|
|
|
|
io.set('logger', {
|
|
|
|
debug: function (str)
|
|
|
|
{
|
2011-11-19 23:14:31 +01:00
|
|
|
socketIOLogger.debug.apply(socketIOLogger, arguments);
|
2011-07-31 19:25:51 +02:00
|
|
|
},
|
|
|
|
info: function (str)
|
|
|
|
{
|
2011-11-19 23:14:31 +01:00
|
|
|
socketIOLogger.info.apply(socketIOLogger, arguments);
|
2011-07-31 19:25:51 +02:00
|
|
|
},
|
|
|
|
warn: function (str)
|
|
|
|
{
|
2011-11-19 23:14:31 +01:00
|
|
|
socketIOLogger.warn.apply(socketIOLogger, arguments);
|
2011-07-31 19:25:51 +02:00
|
|
|
},
|
|
|
|
error: function (str)
|
|
|
|
{
|
2011-11-19 23:14:31 +01:00
|
|
|
socketIOLogger.error.apply(socketIOLogger, arguments);
|
2011-07-31 19:25:51 +02:00
|
|
|
},
|
|
|
|
});
|
2011-07-07 19:15:39 +02:00
|
|
|
|
2011-07-27 15:46:45 +02:00
|
|
|
//minify socket.io javascript
|
|
|
|
if(settings.minify)
|
|
|
|
io.enable('browser client minification');
|
|
|
|
|
2011-07-27 19:52:23 +02:00
|
|
|
var padMessageHandler = require("./handler/PadMessageHandler");
|
|
|
|
var timesliderMessageHandler = require("./handler/TimesliderMessageHandler");
|
2011-06-20 12:44:04 +02:00
|
|
|
|
|
|
|
//Initalize the Socket.IO Router
|
2012-02-25 16:24:39 +01:00
|
|
|
socketIORouter = require("./handler/SocketIORouter");
|
2011-06-20 12:44:04 +02:00
|
|
|
socketIORouter.setSocketIO(io);
|
|
|
|
socketIORouter.addComponent("pad", padMessageHandler);
|
|
|
|
socketIORouter.addComponent("timeslider", timesliderMessageHandler);
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2011-05-14 19:57:07 +02:00
|
|
|
callback(null);
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
2011-05-14 19:57:07 +02:00
|
|
|
]);
|