diff --git a/app.js b/app.js deleted file mode 100644 index df8d1b8..0000000 --- a/app.js +++ /dev/null @@ -1,74 +0,0 @@ -var config = require('./serverconfig'); -var fs = require('fs'); -var SocketServer = require("./socketserver/socketserver"); -var log = new(require('basic-logger'))({ - showTimestamp: true, - prefix: "SocketServer" -}); -var path = require('path'); - -if(!config.setup){ - log.error("Please, setup your server by editing the 'serverconfig.js' file"); - return; -} - -var server = null; - -var webConfig = '// THIS IS AN AUTOMATICALLY GENERATED FILE\n\nvar config=JSON.parse(\'' + JSON.stringify( - { - useSSL: config.useSSL, - serverPort: config.socketServer.port, - selfHosted: true, - serverHost: config.socketServer.host - } - ) + '\')'; - -if (config.hostWebserver){ - fs.writeFileSync(path.join(__dirname, '/webserver/public/lib/js', 'webconfig.js'), webConfig); - var webserver = require('./webserver/app'); - server = (config.socketServer.port == config.webServer.port || config.socketServer.port == '') ? webserver.server : null; -} - -if (config.apis.musiqpad.sendLobbyStats && (!config.apis.musiqpad.key || config.apis.musiqpad.key == '')) { - throw 'In order to send stats to the lobby you must generate an key here: https://musiqpad.com/lounge'; -} - -fs.writeFileSync(path.join(__dirname, '', 'webconfig.js'), webConfig); - -var socketServer = new SocketServer(server); - -process.on('uncaughtException', function(err) { - console.log(err); - console.log(err.stack); - socketServer.gracefulExit(); -}); - -process.on('exit', socketServer.gracefulExit); - -//catches ctrl+c event -process.on('SIGINT', socketServer.gracefulExit); - -function fileExistsSync() { - var exists = false; - try { - exists = fs.statSync(path); - } catch(err) { - exists = false; - } - - return !!exists; -} - -if(process.argv[2] === "--daemon") { - if (fileExistsSync(__dirname + '/pidfile')) { - try { - var pid = fs.readFileSync(__dirname + '/pidfile', { encoding: 'utf-8' }); - process.kill(pid, 0); - process.exit(); - } catch (e) { - fs.unlinkSync(__dirname + '/pidfile'); - } - } - - fs.writeFile(__dirname + '/pidfile', process.pid); -} \ No newline at end of file diff --git a/package.json b/package.json index 5273fb3..9f400a8 100644 --- a/package.json +++ b/package.json @@ -15,17 +15,24 @@ }, "homepage": "https://github.com/musiqpad/mqp-server#readme", "scripts": { - "start": "node ./start.js" + "start": "node ./mqp.js start", + "stop": "node ./mqp.js stop", + "restart": "node ./mqp.js restart", + "log": "node ./mqp.js log", + "update": "node ./mqp.js update" }, "dependencies": { - "basic-logger": "^0.4.4", + "chalk": "^1.0.0", "clean-css": "^3.4.9", + "daemon": "^1.1.0", "deasync": "^0.1.4", + "download-git-repo": "^0.1.2", "durationjs": "^1.1.1", "express": "^4.13.3", "extend": "^3.0.0", + "file-tail": "^0.3.0", "forever": "^0.15.1", - "leveldown": "^1.4.3", + "leveldown": "1.4.4", "levelup": "^1.3.1", "mongodb": "^2.1.16", "mysql": "^2.10.2", @@ -36,7 +43,6 @@ "update-notifier": "^0.7.0", "ws": "^1.0.1", "xoauth2": "^1.1.0", - "boxen": "^0.5.1", - "chalk": "^1.0.0" + "yesno": "0.0.1" } } diff --git a/start.js b/start.js index 9db439b..df8d1b8 100644 --- a/start.js +++ b/start.js @@ -6,38 +6,12 @@ var log = new(require('basic-logger'))({ prefix: "SocketServer" }); var path = require('path'); -var updateNotifier = require('update-notifier'); -var pkg = require('./package.json'); -var boxen = require('boxen'); -var chalk = require('chalk'); if(!config.setup){ log.error("Please, setup your server by editing the 'serverconfig.js' file"); return; } -function checkForUpdates() { - var notifier = updateNotifier({ - pkg, - updateCheckInterval: 0 - }); - if(notifier.update) { - var message = '\n' + boxen('Update available ' + chalk.dim(notifier.update.current) + chalk.reset(' → ') + chalk.green(notifier.update.latest), { - padding: 1, - margin: 1, - borderColor: 'yellow', - borderStyle: 'round' - }); - console.log(message); - } -} - -setInterval(function () { - checkForUpdates() -}, 1000 * 60 * 60 * 2) - -checkForUpdates() - var server = null; var webConfig = '// THIS IS AN AUTOMATICALLY GENERATED FILE\n\nvar config=JSON.parse(\'' + JSON.stringify( @@ -73,3 +47,28 @@ process.on('exit', socketServer.gracefulExit); //catches ctrl+c event process.on('SIGINT', socketServer.gracefulExit); + +function fileExistsSync() { + var exists = false; + try { + exists = fs.statSync(path); + } catch(err) { + exists = false; + } + + return !!exists; +} + +if(process.argv[2] === "--daemon") { + if (fileExistsSync(__dirname + '/pidfile')) { + try { + var pid = fs.readFileSync(__dirname + '/pidfile', { encoding: 'utf-8' }); + process.kill(pid, 0); + process.exit(); + } catch (e) { + fs.unlinkSync(__dirname + '/pidfile'); + } + } + + fs.writeFile(__dirname + '/pidfile', process.pid); +} \ No newline at end of file diff --git a/webserver/app.js b/webserver/app.js index b1ba9b6..180a180 100644 --- a/webserver/app.js +++ b/webserver/app.js @@ -12,15 +12,12 @@ var socketServer = null; if (config.certificate && config.certificate.key && config.certificate.cert){ server = https.createServer(config.certificate, app); - if(config.webServer.redirectHTTP && config.webServer.redirectPort != ''){ + if(config.webServer.redirectHTTP && config.webServer.redirectPort != '') server2 = http.createServer(app); - } -}else{ - server = http.createServer(app); } - -//var server = http.createServer(app); - +else { + server = http.createServer(app); +} app.use(function(req, res, next) { if(!req.secure && config.webServer.redirectHTTP) { @@ -32,9 +29,10 @@ app.use(function(req, res, next) { app.use(express.static(path.resolve(__dirname, 'public'))); app.use('/pads', express.static(path.resolve(__dirname, 'public'))); app.get('/config', function(req, res) { - res.send(fs.readFileSync(__dirname + '/public/lib/js/webconfig.js')); + res.setHeader("Content-Type", "application/javascript"); + res.send(fs.readFileSync(__dirname + '/public/lib/js/webconfig.js')); }); -app.get('/api/room', function(req,res){ +app.get('/api/room', function(req, res) { var roomInfo = { "slug": config.room.slug, "name": config.room.name, @@ -62,4 +60,4 @@ var setSocketServer = function(ss){ }; -module.exports = {app: app, server: server, server2: server2, setSocketServer: setSocketServer}; \ No newline at end of file +module.exports = {app: app, server: server, server2: server2, setSocketServer: setSocketServer};