Ability to categorize networks
This commit is contained in:
@ -7,6 +7,7 @@ var io = require('socket.io');
|
||||
var logger = require('./logger');
|
||||
|
||||
var config = require('../config.json');
|
||||
var servers = require('../servers.json');
|
||||
|
||||
var urlMapping = [];
|
||||
|
||||
@ -34,6 +35,41 @@ function handleRequest(req, res) {
|
||||
message: 'API deprecated.'
|
||||
}));
|
||||
|
||||
res.end();
|
||||
} else if (requestUrl === '/publicConfig.json') {
|
||||
res.setHeader('Content-Type', 'application/javascript');
|
||||
|
||||
var categories = config.serverCategories;
|
||||
|
||||
// Legacy support for people without categories configured.
|
||||
if (!categories) {
|
||||
categories = {
|
||||
'default': 'All Networks'
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
var entry = servers[i];
|
||||
|
||||
if (!entry.category) {
|
||||
entry.category = 'default';
|
||||
|
||||
logger.warn('%s has no category, defaulting!', entry.name);
|
||||
} else if (!categories[entry.category]) {
|
||||
logger.warn('%s has an unknown category (%s), defaulting!', entry.name, entry.category);
|
||||
|
||||
entry.category = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
var publicConfig = {
|
||||
categories: categories,
|
||||
graphDuration: config.graphDuration,
|
||||
servers: servers
|
||||
};
|
||||
|
||||
res.write('setPublicConfig(' + JSON.stringify(publicConfig) + ');');
|
||||
|
||||
res.end();
|
||||
} else if (requestUrl in urlMapping) {
|
||||
var file = urlMapping[requestUrl];
|
||||
|
Reference in New Issue
Block a user