Only one config for client and server.

This commit is contained in:
Your Name 2014-06-06 21:22:57 +02:00
parent 46717e14ae
commit a2723c6b12
8 changed files with 62 additions and 28 deletions

View file

@ -82,6 +82,10 @@ module.exports = function (grunt) {
context: '/api/', context: '/api/',
host: '127.0.0.1', host: '127.0.0.1',
port: 8080 port: 8080
}, {
context: '/config.js',
host: '127.0.0.1',
port: 8080
}], }],
livereload: { livereload: {
options: { options: {

View file

@ -44,7 +44,6 @@
<!-- build:js scripts/scripts.js --> <!-- build:js scripts/scripts.js -->
<script src="scripts/app.js"></script> <script src="scripts/app.js"></script>
<script src="scripts/libs.js"></script> <script src="scripts/libs.js"></script>
<script src="scripts/config.js"></script>
<script src="scripts/controllers/main.js"></script> <script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/newNodeCtrl.js"></script> <script src="scripts/controllers/newNodeCtrl.js"></script>
@ -60,5 +59,7 @@
<script src="scripts/validation/constraints.js"></script> <script src="scripts/validation/constraints.js"></script>
<!-- endbuild --> <!-- endbuild -->
<script src="config.js"></script>
</body> </body>
</html> </html>

View file

@ -1,21 +0,0 @@
'use strict';
angular.module('ffffng')
.factory('config', function () {
return {
community: {
name: 'Freifunk Hamburg',
domain: 'hamburg.freifunk.net',
contactEmail: 'kontakt@hamburg.freifunk.net'
},
map: {
graphUrl: 'http://graph.hamburg.freifunk.net/graph.html',
mapUrl: 'http://graph.hamburg.freifunk.net/geomap.html'
},
coordsSelector: {
lat: 53.565278,
lng: 10.001389,
defaultZoom: 10
}
};
});

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('ffffng').factory('app', function (fs) { angular.module('ffffng').factory('app', function (fs, config, _) {
var express = require('express'); var express = require('express');
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var compress = require('compression'); var compress = require('compression');
@ -10,8 +10,34 @@ angular.module('ffffng').factory('app', function (fs) {
app.use(bodyParser()); app.use(bodyParser());
var clientDir = __dirname + '/../client'; var clientDir = __dirname + '/../client';
var templateDir = __dirname + '/templates';
var jsTemplateFiles = [
'/config.js'
];
app.use(compress()); app.use(compress());
function serveTemplate(mimeType, req, res, next) {
return fs.readFile(templateDir + '/' + req.path, 'utf8', function (err, body) {
if (err) {
return next(err);
}
res.writeHead(200, {'Content-Type': mimeType});
res.end(_.template(body, { config: config.client }));
return null; // to suppress warning
});
}
app.use( function (req, res, next) {
if (jsTemplateFiles.indexOf(req.path) >= 0) {
return serveTemplate('application/javascript', req, res, next);
}
return next();
});
app.use('/', express.static(clientDir + '/')); app.use('/', express.static(clientDir + '/'));
return app; return app;

View file

@ -2,7 +2,25 @@
angular.module('ffffng').factory('config', function () { angular.module('ffffng').factory('config', function () {
return { return {
server: {
port: 8080, port: 8080,
peersPath: '/tmp/peers' peersPath: '/tmp/peers'
},
client: {
community: {
name: 'Freifunk Hamburg',
domain: 'hamburg.freifunk.net',
contactEmail: 'kontakt@hamburg.freifunk.net'
},
map: {
graphUrl: 'http://graph.hamburg.freifunk.net/graph.html',
mapUrl: 'http://graph.hamburg.freifunk.net/geomap.html'
},
coordsSelector: {
lat: 53.565278,
lng: 10.001389,
defaultZoom: 10
}
}
}; };
}); });

View file

@ -25,6 +25,6 @@ require('./validation/validator');
angular.injector(['ffffng']).invoke(function (config, app, Router) { angular.injector(['ffffng']).invoke(function (config, app, Router) {
Router.init(); Router.init();
app.listen(config.port, '::'); app.listen(config.server.port, '::');
module.exports = app; module.exports = app;
}); });

View file

@ -16,7 +16,7 @@ angular.module('ffffng')
} }
function findNodeFiles(pattern) { function findNodeFiles(pattern) {
return glob.sync(config.peersPath + '/' + pattern.toLowerCase()); return glob.sync(config.server.peersPath + '/' + pattern.toLowerCase());
} }
function isDuplicate(pattern, token) { function isDuplicate(pattern, token) {
@ -52,7 +52,7 @@ angular.module('ffffng')
function writeNodeFile(isUpdate, token, node, callback) { function writeNodeFile(isUpdate, token, node, callback) {
var filename = var filename =
config.peersPath + '/' + (node.hostname + '@' + node.mac + '@' + node.key + '@' + token).toLowerCase(); config.server.peersPath + '/' + (node.hostname + '@' + node.mac + '@' + node.key + '@' + token).toLowerCase();
var data = ''; var data = '';
_.each(linePrefixes, function (prefix, key) { _.each(linePrefixes, function (prefix, key) {

View file

@ -0,0 +1,6 @@
'use strict';
angular.module('ffffng')
.factory('config', function () {
return <%= JSON.stringify(config) %>;
});