diff --git a/app.js b/app.js index 580fcfc..ede997b 100644 --- a/app.js +++ b/app.js @@ -13,6 +13,7 @@ var Manager = require('./lib/manager') var Missions = require('./lib/missions') var Mods = require('./lib/mods') var Logs = require('./lib/logs') +var Settings = require('./lib/settings') var app = express() var server = require('http').Server(app) @@ -43,15 +44,18 @@ var missions = new Missions(config) var mods = new Mods(config) mods.updateMods() +var settings = new Settings(config) + app.use('/api/logs', require('./routes/logs')(logs)) app.use('/api/missions', require('./routes/missions')(missions)) app.use('/api/mods', require('./routes/mods')(mods)) app.use('/api/servers', require('./routes/servers')(manager, mods)) -app.use('/api/settings', require('./routes/settings')(config)) +app.use('/api/settings', require('./routes/settings')(settings)) io.on('connection', function (socket) { socket.emit('mods', mods.mods) socket.emit('servers', manager.getServers()) + socket.emit('settings', settings.getPublicSettings()) }) mods.on('mods', function (mods) { diff --git a/lib/settings.js b/lib/settings.js new file mode 100644 index 0000000..f9ae955 --- /dev/null +++ b/lib/settings.js @@ -0,0 +1,11 @@ +var _ = require('lodash') + +var Settings = function (config) { + this.config = config +} + +Settings.prototype.getPublicSettings = function () { + return _.pick(this.config, ['game', 'path', 'type']) +} + +module.exports = Settings diff --git a/public/js/app/router.js b/public/js/app/router.js index d530170..97dc156 100644 --- a/public/js/app/router.js +++ b/public/js/app/router.js @@ -37,7 +37,6 @@ define(function (require) { initialize: function () { layoutView.navigation.show(new NavigationView({settings: settings, servers: servers})); missions.fetch(); - settings.fetch(); var initialized = false; @@ -53,6 +52,9 @@ define(function (require) { Backbone.history.start(); } }); + socket.on('settings', function (_settings) { + settings.set(_settings); + }); }, home: function () { diff --git a/routes/settings.js b/routes/settings.js index dc951b0..a29e5a4 100644 --- a/routes/settings.js +++ b/routes/settings.js @@ -1,11 +1,10 @@ var express = require('express') -var _ = require('lodash') -module.exports = function (config) { +module.exports = function (settings) { var router = express.Router() router.get('/', function (req, res) { - res.json(_.pick(config, ['game', 'path', 'type'])) + res.json(settings.getPublicSettings()) }) return router