public
anonymous / gist:5777728
Created

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/*jslint node:true, nomen:true */
 
var combo = require("combo-js-css"),
defaultConfig = {
baseComboPath:"/cb",
jsComboPath:"/js/",
cssComboPath:"/css/",
pathSets:[
{
"rootPath":"/mojits",
"cssRootPath":"/",
"jsRootPath":"/"
},
{
"rootPath":"/assets",
"cssRootPath":"/",
"jsRootPath":"/"
}
]
},
config;
 
function setupConfig(app){
var store = app.store,
appConfig = store.getStaticAppConfig(),
yuiDetails = store.yui.getYUIURLDetails(),
staticDetails = store.getAllURLDetails();
config = merge(
defaultConfig,
appConfig.comboJsCss,
{
staticDescriptor: merge(yuiDetails, staticDetails),
staticStore: store.yui.resContents
}
);
for( var n in store.yui.resContents){
console.log(n);
}
combo.config.updateConfigFromParams(config);
}
 
function merge(){
var finalObj = {};
for( var i = 0, ln = arguments.length; i < ln; i++){
if(arguments[i]){
copy(finalObj, arguments[i]);
}
}
return finalObj;
}
 
function copy(tar, src){
for( var n in src){
if(src.hasOwnProperty(n)){
tar[n] = src[n];
}
}
}
 
module.exports = function (req, res, next) {
if(!config){
setupConfig(req.app);
}
if(!req.url.indexOf(config.baseComboPath + config.jsComboPath)){
console.log("serving JS from combo service");
combo.combo.comboReq(req, res, combo.config.types.JS, combo.config);
return true;
}
if(!req.url.indexOf(config.baseComboPath + config.jsComboPath)){
combo.combo.comboReq(req, res, combo.config.types.CSS, combo.config);
return true;
}
next();
return false;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.