public
anonymous / gist:5775771
Created

  • Download Gist
gistfile1.md
Markdown

Hey, Carldy

I've been trying to work around this problem by trying to implement my own combo service as middleware. But I have run into 3 issues.

1) User middle ware is not initialized the same way and core Mojito middle ware is:

example from mojito-handler-static.js:

module.exports = function (config) {
    return staticProvider(config.store, config.logger, config.Y);
};

This middleware is initialized in the bootstrap of mojito. Where as my middleware is only run at request time and cannot return a routehandler.

example from my middleware:

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;
};

This means I have no access to init time vars and I have to do my config at request time which sucks. And lead me to my second issue.

2) When trying to implement my own combo service I had to deal with the odd request paths and the static YUI store. These aren't too much of an issue if you have both the YUI and App static descriptor hashes.

The problem is the store methods that provides these descriptors only returns a blank object after init time.

In store.server.js the optomizeForEnvirontment clears out all the RVs.

optimizeForEnvironment: function() {
    this._packagesVisited = {};
    this._appRVs = [];
    this._mojitRVs = {};
},

Clearing these guys out makes sense but the problem is the output of store.getAllURLDetails() isn't made public it's called once in the static middleware and stored in a local variable there. A simple and logical fix would be to store this crucial data so that it's available.

I would propose changing getAllURLDetails from this:

getAllURLDetails: function() {
    var r,
        res,
        ress,
        m,
        mojit,
        mojits,
        urls = {};
...

To this:

getAllURLDetails: function() {
    var r,
        res,
        ress,
        m,
        mojit,
        mojits,
        urls;

    if(this._urls){
        return this._urls;
    }

    urls = this._urls = {};

One this isn't the kind of operation you would need to run twice, given how the store preloader works. And two this wouldn't require any more memory. It would just allow that function to return data after Mojito is bootstrapped.

3) It seems as though the YUI config json isn't properly handling ampersands in the application json.

Example:

"yui":{
    "config":{
        "groups":{
            "app":{
                "comboBase": "/cb/js/?ver=1&",
                "comboSep": "&",
                "root": ""
            }
        }
    }
},

results in this being dropped on the page:

"comboBase":"/cb/js/?ver=1\\u0026","comboSep":"&"

This also happens with urls in the modules them selves:

"yui":{
    "config":{
        "groups":{
            "vendor-scripts":{
                "modules":{
                    "buzzfeed":{
                        "fullpath":"http://ct.buzzfeed.com/wd/UserWidget?u=XXXXXXXX&to=1&or=vb&wid=1&cb=1332869026943"
                    },

Which results in a request like this in the page:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
http://ct.buzzfeed.com/wd/UserWidget?u=XXXXXXXX\u0026to=1\u0026or=vb\u0026wid=1\u0026cb=1332869026943

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.