2014-05-12 20:08:19 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-06 21:22:57 +02:00
|
|
|
angular.module('ffffng').factory('app', function (fs, config, _) {
|
2014-05-12 20:08:19 +02:00
|
|
|
var express = require('express');
|
2014-06-06 14:57:20 +02:00
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var compress = require('compression');
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
var app = express();
|
|
|
|
|
2014-08-10 11:54:25 +02:00
|
|
|
app.use(bodyParser.json());
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
var clientDir = __dirname + '/../client';
|
2014-06-06 21:22:57 +02:00
|
|
|
var templateDir = __dirname + '/templates';
|
|
|
|
|
|
|
|
var jsTemplateFiles = [
|
|
|
|
'/config.js'
|
|
|
|
];
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2014-06-06 14:57:20 +02:00
|
|
|
app.use(compress());
|
2014-06-06 21:22:57 +02:00
|
|
|
|
|
|
|
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});
|
2016-05-16 13:33:49 +02:00
|
|
|
res.end(_.template(body)( { config: config.client }));
|
2014-06-06 21:22:57 +02:00
|
|
|
|
|
|
|
return null; // to suppress warning
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:40:57 +02:00
|
|
|
app.use(function (req, res, next) {
|
2014-06-06 21:22:57 +02:00
|
|
|
if (jsTemplateFiles.indexOf(req.path) >= 0) {
|
|
|
|
return serveTemplate('application/javascript', req, res, next);
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
app.use('/', express.static(clientDir + '/'));
|
|
|
|
|
|
|
|
return app;
|
|
|
|
});
|