asset-rack
asset-rack copied to clipboard
Express 4
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 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)
Never mind, looks like it is choking on coffee-script not being compiled now
Maybe I'm using a newer version of CoffeeScript?
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.
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.
Good catch.
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...)
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.