Skip to content

Instantly share code, notes, and snippets.

@MitMaro
Last active March 26, 2018 18:38
Show Gist options
  • Save MitMaro/7c9340d20606d3687ea09dfd498f27cd to your computer and use it in GitHub Desktop.
Save MitMaro/7c9340d20606d3687ea09dfd498f27cd to your computer and use it in GitHub Desktop.
feathers-subapp-context-lost
node_modules/

Instructions

npm install
node index
'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));
{
"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