Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions node/server.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,35 @@
* limitations under the License.
*/

//export app and handle mounting
var express = require('express');
var app = express.createServer();
var fs = require('fs');
var ioApp = app;


var settings = require('./utils/Settings');
var minify = require('./utils/Minify');
var db = require('./db/DB');

exports.helpExpress = function(opts) {
console.log('helping express', opts);
if (opts.basepath) app.set('basepath',opts.basepath);
if (opts.settings) {
fs.writeFile(__dirname+'/../settings.json',JSON.stringify(opts.settings))
}
settings = require('./utils/Settings');
minify = require('./utils/Minify');
db = require('./db/DB');
return app;
}

var ERR = require("async-stacktrace");
var log4js = require('log4js');
var os = require("os");
var socketio = require('socket.io');
var fs = require('fs');
var settings = require('./utils/Settings');
var db = require('./db/DB');
var async = require('async');
var express = require('express');
var path = require('path');
var minify = require('./utils/Minify');
var formidable = require('formidable');
var apiHandler;
var exportHandler;
Expand Down Expand Up @@ -60,6 +78,11 @@ console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues")

var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";

app.mounted(function(other){
ioApp = other;
console.log('mounted pad');
});

//cache 6 hours
exports.maxAge = 1000*60*60*6;

Expand All @@ -76,7 +99,7 @@ async.waterfall([
function (callback)
{
//create server
var app = express.createServer();
//var app = express.createServer();

//load modules that needs a initalized db
readOnlyManager = require("./db/ReadOnlyManager");
Expand Down Expand Up @@ -425,9 +448,10 @@ async.waterfall([
});

//let the server listen
app.listen(settings.port, settings.ip);
console.log("Server is listening at " + settings.ip + ":" + settings.port);

if (!module.parent) {
app.listen(settings.port, settings.ip);
console.log("Server is listening at " + settings.ip + ":" + settings.port);
}
var onShutdown = false;
var gracefulShutdown = function(err)
{
Expand All @@ -447,7 +471,9 @@ async.waterfall([
console.log("graceful shutdown...");

//stop the http server
app.close();
if(!module.parent) {
app.close();
}

//do the db shutdown
db.db.doShutdown(function()
Expand All @@ -473,7 +499,7 @@ async.waterfall([
process.on('uncaughtException', gracefulShutdown);

//init socket.io and redirect all requests to the MessageHandler
var io = socketio.listen(app);
var io = socketio.listen(ioApp);

//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
Expand Down Expand Up @@ -510,7 +536,7 @@ async.waterfall([
socketIORouter.setSocketIO(io);
socketIORouter.addComponent("pad", padMessageHandler);
socketIORouter.addComponent("timeslider", timesliderMessageHandler);

callback(null);
}
]);
17 changes: 9 additions & 8 deletions node/utils/Minify.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports.minifyJS = function(req, res, jsFilename)
//find out the highest modification date
function(callback)
{
var folders2check = ["../static/css","../static/js"];
var folders2check = [__dirname+"/../../static/css",__dirname+"/../../static/js"];

//go trough this two folders
async.forEach(folders2check, function(path, callback)
Expand Down Expand Up @@ -102,7 +102,7 @@ exports.minifyJS = function(req, res, jsFilename)
function(callback)
{
//check the modification time of the minified js
fs.stat("../var/minified_" + jsFilename, function(err, stats)
fs.stat(__dirname+"/../../var/minified_" + jsFilename, function(err, stats)
{
if(err && err.code != "ENOENT")
{
Expand All @@ -127,7 +127,7 @@ exports.minifyJS = function(req, res, jsFilename)
{
async.forEach(jsFiles, function (item, callback)
{
fs.readFile("../static/js/" + item, "utf-8", function(err, data)
fs.readFile(__dirname+"/../../static/js/" + item, "utf-8", function(err, data)
{
if(ERR(err, callback)) return;
fileValues[item] = data;
Expand All @@ -152,9 +152,10 @@ exports.minifyJS = function(req, res, jsFilename)
{
var filename = item.match(/"[^"]*"/g)[0].substr(1);
filename = filename.substr(0,filename.length-1);

filename = __dirname+"/../"+filename

var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length);

//read the included file
fs.readFile(filename, "utf-8", function(err, data)
{
Expand Down Expand Up @@ -205,7 +206,7 @@ exports.minifyJS = function(req, res, jsFilename)
//write the results plain in a file
function(callback)
{
fs.writeFile("../var/minified_" + jsFilename, result, "utf8", callback);
fs.writeFile(__dirname+"/../../var/minified_" + jsFilename, result, "utf8", callback);
},
//write the results compressed in a file
function(callback)
Expand All @@ -219,7 +220,7 @@ exports.minifyJS = function(req, res, jsFilename)

if(ERR(err, callback)) return;

fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback);
fs.writeFile(__dirname+"/../../var/minified_" + jsFilename + ".gz", compressedResult, callback);
});
}
//skip this step on windows
Expand Down Expand Up @@ -262,7 +263,7 @@ exports.minifyJS = function(req, res, jsFilename)
//read all js files
async.forEach(jsFiles, function (item, callback)
{
fs.readFile("../static/js/" + item, "utf-8", function(err, data)
fs.readFile(__dirname+"/../../static/js/" + item, "utf-8", function(err, data)
{
if(ERR(err, callback)) return;
fileValues[item] = data;
Expand Down
17 changes: 13 additions & 4 deletions node/utils/Settings.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ exports.abiwordAvailable = function()
}
}

//read the settings sync
var settingsStr = fs.readFileSync("../settings.json").toString();
var settingsStr = '{}';

//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
try
{
//read the settings sync
settingsStr = fs.readFileSync(__dirname+"/../../settings.json").toString();

//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
}
catch(e)
{
console.warn('could not read '+__dirname+"/../../settings.json")
}

//try to parse the settings
var settings;
Expand Down
4 changes: 2 additions & 2 deletions static/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@
function go2Name()
{
var padname = document.getElementById("padname").value;
padname.length > 0 ? window.location = "p/" + padname : alert("Please enter a name")
padname.length > 0 ? window.location = window.location + "/p/" + padname : alert("Please enter a name")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here, please don't change this paths

}

function go2Random()
{
window.location = "p/" + randomPadName();
window.location = window.location + "/p/" + randomPadName();
}

function randomPadName()
Expand Down
3 changes: 2 additions & 1 deletion static/js/pad2.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ function handshake()
//find out in which subfolder we are
var resource = loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "socket.io";
//connect
console.log('create socket',url,resource)
socket = io.connect(url, {
resource: resource,
resource: 'socket.io',
'max reconnection attempts': 3
});

Expand Down
2 changes: 1 addition & 1 deletion static/pad.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var clientVars = {};
// ]]>
</script>
<script src="../socket.io/socket.io.js"></script>
<script src="/socket.io/socket.io.js"></script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep relative paths

<script src="../minified/pad.js"></script>
<link href="../static/custom/pad.css" rel="stylesheet">
<script src="../static/custom/pad.js"></script>
Expand Down