npm install
node index
Last active
March 26, 2018 18:38
-
-
Save MitMaro/7c9340d20606d3687ea09dfd498f27cd to your computer and use it in GitHub Desktop.
feathers-subapp-context-lost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const feathers = require('@feathersjs/feathers'); | |
const api1 = feathers(); | |
let api1Params; | |
let api2Params; | |
api1.hooks({ | |
async before(context) { | |
api1Params = context.params; | |
throw new Error('Error in api1 before hook'); | |
}, | |
}); | |
api1.use('/service1', { | |
find: () => 'service1 success' | |
}); | |
const api2 = feathers(); | |
api2.hooks({ | |
before(context) { | |
api2Params = context.params; | |
context.params.foo = 'bar' | |
}, | |
error(context) { | |
console.log('api2 error hook'); | |
console.log('params from api1 service is the same as context params (should be false)? ', api1Params === context.params); | |
console.log('params from api2 service is the same as context params (should be true)? ', api2Params === context.params); | |
console.log('path (should equal /service2):', context.path); | |
console.log('params.foo (should equal bar):', context.params.foo); | |
}, | |
}); | |
api2.use('/service2', { | |
async find(params) { | |
console.log('service2 call params.foo (should equal bar):', params.foo); | |
// this will throw an error from the api1 before hook | |
await api1.service('/service1').find({}); | |
return 'service2 success'; | |
}, | |
}); | |
api2.service('/service2').find().then(console.log).catch(e => console.log(e.message)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "feathers-subapp-context-error", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@feathersjs/feathers": "^3.1.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment