A lot of us are building impressive configuration objects to pass to
apostrophe-site, like this:
var site = require('apostrophe-site')({
pages: {
load: [
quiteALotOfFunctions
]
}
});
It's natural to want to access things like site.apos.get inside those
functions. And you can do it, because "site" is defined here in
app.js.
But it's also natural to want to break up app.js into multiple files
using require. And right now, you can't really do that with functions,
because at the time "require" is called, "site" doesn't exist yet.
We've just published a fix for this problem. You can now write:
var site = require('apostrophe-site')();
site.init({
pages: {
load: [
quiteALotOfFunctions
]
}
});
By breaking the creation and configuration of your site object into
two steps, we make it easy to use require:
var site = require('apostrophe-site')();
site.init({
// ... regular stuff ...
pages: {
load: require('./lib/loaders.js')(site)
}
});
// in lib/loaders.js
module.exports = function(site) {
return [
function(req, callback) {
site.apos.doSomethingInteresting(callback);
}
]
};
Hope you find this as helpful as we do!
--
THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE |
(215) 755-1330 |
punkave.com