diff --git a/lib/index.js b/lib/index.js index f1db0cd..5279ff3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -151,7 +151,7 @@ function get_route_handler(fn) { const data = { params: req.params, query: req.query }; if (mod.preload) { - const promise = Promise.resolve(mod.preload(data)).then(preloaded => { + const promise = Promise.resolve(mod.preload(req)).then(preloaded => { Object.assign(data, preloaded); return mod.render(data); }); diff --git a/test/app/routes/show-url.html b/test/app/routes/show-url.html new file mode 100644 index 0000000..f0d4bb0 --- /dev/null +++ b/test/app/routes/show-url.html @@ -0,0 +1,9 @@ +
URL is {{url}}
+ + \ No newline at end of file diff --git a/test/common/test.js b/test/common/test.js index a15fe65..c6f8bf2 100644 --- a/test/common/test.js +++ b/test/common/test.js @@ -11,7 +11,7 @@ run('development'); function run(env) { describe(`env=${env}`, function () { - this.timeout(5000); + this.timeout(20000); let PORT; let server; @@ -267,6 +267,14 @@ function run(env) { 'About this site' ); }); + + it('passes entire request object to preload', async () => { + const html = await nightmare + .goto(`${base}/show-url`) + .evaluate(() => document.querySelector('p').innerHTML); + + assert.equal(html, `URL is /show-url`); + }); }); describe('headers', () => {