I'm trying to override Express view lookup function, but can't manage to do it. The goal is to be able to be able to look for templates in multiple directories.
What I'm trying to do is, in bootstrap.js
:
function bootstrap(express) {
var originalLookup = express.View.prototype.lookup;
express.View.prototype.lookup = function(path) {
console.log('Requested for', path);
return originalLookup(path);
};
};
module.exports = bootstrap;
My app.js
code is:
var express = require('express'),
routes = require('./routes'),
bootstrap = require('./bootstrap'),
app = module.exports = express.createServer();
// Configuration
require('./config/environment.js')(app, express);
// Bootstrap
bootstrap(express);
// Routes
require('./config/routes.js')(app);
// Start
app.listen(3000);
In my bootstrap.js
code, express.View.prototype.lookup is undefined. I can't understand why. What did I do wrong?
I'm just beginning with node.js and "advanced" Javascript. And I have to admit I'm kinda lost here.
Thanks.
In current version (2.5.9) it's not View.prototype.lookup, it's just View.lookup.
~: ) node
> require('express').View
{ [Function: View]
register: [Function],
compile: [Function],
lookup: [Function] }
> require('express').View.lookup
[Function]