asset-rack icon indicating copy to clipboard operation
asset-rack copied to clipboard

Express 4

Open johngeorgewright opened this issue 10 years ago • 8 comments

Now that Express 4 no longer excepts objects as middleware we have to use callbacks instead.

To keep asset-rack working in express 4, with some kind of fallback capabilities for express 3, I'm proposing to specify the Rack#handle method when adding the rack/asset as middleware. I've also upgraded CoffeeScript, so I could easily bind the class's method to any instance of it with the new fat-arrow syntax.

Another problem is the express.Response#locals property is no longer a function. Therefore I've added the assets' "locals" property directly to the express instance.

johngeorgewright avatar Apr 19 '14 16:04 johngeorgewright

@johngeorgewright I am getting an error when trying to use this with express 4.1.1

TypeError: Property 'locals' of object #<ServerResponse> is not a function
    at Layer.exports.Rack.Rack.handle (/Users/ryanbillingsley/Dev/covert-deer/node_modules/asset-rack/compiled/rack.js:79:16)

ryanbillingsley avatar May 06 '14 15:05 ryanbillingsley

Never mind, looks like it is choking on coffee-script not being compiled now

ryanbillingsley avatar May 06 '14 16:05 ryanbillingsley

Maybe I'm using a newer version of CoffeeScript?

johngeorgewright avatar May 07 '14 09:05 johngeorgewright

The problem is in the switch.js

try {
    module.exports = require('./compiled');
} catch(error) {
    //require('./node_modules/coffee-script');
    require('coffee-script');
    module.exports = require('./lib');
}

require is failing to find the module './lib'

It could be because I am loading the module in through git and not through a module, not sure.

ryanbillingsley avatar May 08 '14 22:05 ryanbillingsley

I think this would be the problem https://github.com/jashkenas/coffeescript/pull/3279

Coffee-script introduced a breaking change to how requiring coffee-script works.

ryanbillingsley avatar May 09 '14 00:05 ryanbillingsley

Good catch.

johngeorgewright avatar May 09 '14 08:05 johngeorgewright

This is failing for me on both the latest version of Express (4.3.2) and the version listed here (4.1.1), with a request that never seems to get handled (server just hangs on all requests...)

martindale avatar May 30 '14 20:05 martindale

Hey @martindale, are you giving the #handle method to express#use?

https://github.com/johngeorgewright/asset-rack/blob/express-4/README.md#getting-started

I think that's what was happening to me until I made this pull request.

johngeorgewright avatar Jun 02 '14 08:06 johngeorgewright