mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-17 13:14:54 +00:00
Merge pull request #54 from sveltejs/preload-req
pass server request object to preload
This commit is contained in:
@@ -151,7 +151,7 @@ function get_route_handler(fn) {
|
|||||||
const data = { params: req.params, query: req.query };
|
const data = { params: req.params, query: req.query };
|
||||||
|
|
||||||
if (mod.preload) {
|
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);
|
Object.assign(data, preloaded);
|
||||||
return mod.render(data);
|
return mod.render(data);
|
||||||
});
|
});
|
||||||
|
|||||||
9
test/app/routes/show-url.html
Normal file
9
test/app/routes/show-url.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<p>URL is {{url}}</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
preload({ url }) {
|
||||||
|
return { url };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -11,7 +11,7 @@ run('development');
|
|||||||
|
|
||||||
function run(env) {
|
function run(env) {
|
||||||
describe(`env=${env}`, function () {
|
describe(`env=${env}`, function () {
|
||||||
this.timeout(5000);
|
this.timeout(20000);
|
||||||
|
|
||||||
let PORT;
|
let PORT;
|
||||||
let server;
|
let server;
|
||||||
@@ -267,6 +267,14 @@ function run(env) {
|
|||||||
'About this site'
|
'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', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user