Merge pull request #115 from Dahlgren/feature/socket-settings

Push settings with socket connection
This commit is contained in:
Björn Dahlgren 2018-08-18 12:42:47 +02:00 committed by GitHub
commit e16b558df6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

6
app.js
View File

@ -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) {

11
lib/settings.js Normal file
View File

@ -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

View File

@ -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 () {

View File

@ -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