Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2013 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5777728 to your computer and use it in GitHub Desktop.
Save anonymous/5777728 to your computer and use it in GitHub Desktop.
/*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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment