From b66f624f01df142af96bbbda826cd32d9ee37a9f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 30 Dec 2017 17:31:07 -0500 Subject: [PATCH] pass server request object to preload --- lib/index.js | 2 +- test/app/routes/show-url.html | 9 +++++++++ test/common/test.js | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/app/routes/show-url.html 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..7161a01 100644 --- a/test/common/test.js +++ b/test/common/test.js @@ -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', () => {