2015-02-27 20:50:19 +00:00
|
|
|
'use strict';
|
2015-02-27 14:20:01 +00:00
|
|
|
|
|
|
|
var express = require('express');
|
|
|
|
var async = require('async');
|
|
|
|
var path = require('path');
|
|
|
|
var assets = require('../lib/node-ff-assets');
|
|
|
|
|
|
|
|
function buildAssets(server,callbackDone) {
|
2015-03-14 18:01:46 +00:00
|
|
|
var singleResult = 'false' !== process.env.DEV_ASSETS_SINGLE_RESULT;
|
|
|
|
var assetsConfig = require('./example-assets.json');
|
2015-02-27 14:20:01 +00:00
|
|
|
assets.build({
|
|
|
|
assets: {
|
|
|
|
js: {
|
2015-03-14 18:01:46 +00:00
|
|
|
configCreate: assets.factory.builder.configCreate.fromJSON(assetsConfig,'js'),
|
2015-02-27 14:20:01 +00:00
|
|
|
configFill: function (config, callback) {
|
|
|
|
async.series([
|
|
|
|
assets.factory.lib.async.pushLinkSources(config, '/static/js/', 'www_static/js/'),
|
|
|
|
assets.factory.lib.async.pushLinkSources(config, '/static/js/controller/', 'www_static/js/controller/'),
|
|
|
|
],callback);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
css: {
|
2015-03-14 18:01:46 +00:00
|
|
|
configCreate: assets.factory.builder.configCreate.fromJSON(assetsConfig,'css'),
|
2015-02-27 14:20:01 +00:00
|
|
|
configFill: function (config, callback) {
|
|
|
|
async.series([
|
2015-03-14 18:01:46 +00:00
|
|
|
assets.factory.lib.async.pushLinkSources(config, '/static/css/', 'www_static/css/'),
|
2015-02-27 14:20:01 +00:00
|
|
|
],callback);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-03-14 18:01:46 +00:00
|
|
|
assemblerCreate: assets.factory.builder.assemblerCreate.readFileRegex(),
|
2015-02-27 14:20:01 +00:00
|
|
|
assemblerFill: function (assembler, callback) {
|
|
|
|
var serverResultKey = 'ff_assets_'+assembler.config.assetType;
|
|
|
|
assembler.on ('log', assets.factory.assembler.event.log.console(assembler.config.assetType));
|
|
|
|
assembler.on ('result', assets.factory.assembler.event.result.objectSet(server,serverResultKey));
|
2015-03-14 18:01:46 +00:00
|
|
|
assembler.config.linkTargetSingleResult = singleResult;
|
2015-02-27 14:20:01 +00:00
|
|
|
callback();
|
|
|
|
},
|
|
|
|
},callbackDone);
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:01:46 +00:00
|
|
|
function renderTemplatePath(viewPath) {
|
2015-02-27 20:50:19 +00:00
|
|
|
return function (req, res) {
|
2015-03-14 18:01:46 +00:00
|
|
|
res.locals.query = req.query;
|
|
|
|
var qi = req.url.indexOf('?');
|
|
|
|
if (qi === -1) {
|
|
|
|
qi = req.url.length;
|
2015-02-27 14:20:01 +00:00
|
|
|
}
|
2015-03-14 18:01:46 +00:00
|
|
|
res.render(viewPath + req.url.substring(req.route.path.length-1, qi));
|
2015-02-27 20:50:19 +00:00
|
|
|
};
|
2015-02-27 14:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderPage(server) {
|
2015-02-27 20:50:19 +00:00
|
|
|
return function (req, res) {
|
2015-02-27 14:20:01 +00:00
|
|
|
res.render('index', {
|
2015-03-09 19:31:31 +00:00
|
|
|
pageTitle: 'node-ff-assets example',
|
|
|
|
pageKeywords: 'node,ff,assets,example,ui',
|
|
|
|
pageCssFiles: server.get('ff_assets_css'),
|
|
|
|
pageJsFiles: server.get('ff_assets_js'),
|
2015-02-27 14:20:01 +00:00
|
|
|
});
|
2015-02-27 20:50:19 +00:00
|
|
|
};
|
2015-02-27 14:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function sendRedirect() {
|
2015-02-27 20:50:19 +00:00
|
|
|
return function (req, res) {
|
2015-02-27 14:20:01 +00:00
|
|
|
res.redirect('/example-ui');
|
2015-02-27 20:50:19 +00:00
|
|
|
};
|
2015-02-27 14:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var server = express();
|
|
|
|
buildAssets(server,function(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
console.info('Server assets done.');
|
|
|
|
|
2015-03-09 19:31:31 +00:00
|
|
|
server.set('view engine', 'ejs');
|
2015-03-14 18:01:46 +00:00
|
|
|
server.set('views', path.join(__dirname,'www_views'));
|
|
|
|
server.use('/static', express.static(path.join(__dirname,'www_static')));
|
|
|
|
server.use('/static/module/bootstrap', express.static(path.join(__dirname,'node_modules/bootstrap/dist')));
|
|
|
|
server.use('/static/module/flot', express.static(path.join(__dirname,'node_modules/flot')));
|
2015-02-27 14:20:01 +00:00
|
|
|
|
|
|
|
server.get('/', sendRedirect());
|
2015-03-14 18:01:46 +00:00
|
|
|
server.get('/example-ui/thtml/*', renderTemplatePath('thtml/'));
|
2015-02-27 14:20:01 +00:00
|
|
|
server.get('/example-ui', renderPage(server));
|
|
|
|
server.get('/example-ui/*', renderPage(server)); // must be last; for HTML5 history
|
|
|
|
console.info('Server config done.');
|
|
|
|
|
|
|
|
server.listen(8080);
|
|
|
|
console.info('Server started on port 8080');
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
version: 'example'
|
|
|
|
};
|