Ability to categorize networks

This commit is contained in:
Cryptkeeper
2016-02-06 17:34:33 -06:00
parent d6d59cad12
commit 143e99876a
8 changed files with 416 additions and 315 deletions

View File

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