|
| 1 | +import feathers from 'feathers'; |
| 2 | +import primus from '../src'; |
| 3 | +import memory from 'feathers-memory'; |
| 4 | + |
| 5 | +function todoService() { |
| 6 | + return memory().extend({ |
| 7 | + get: function(id, params, callback) { |
| 8 | + if(params.query.error) { |
| 9 | + return callback(new Error('Something went wrong')); |
| 10 | + } |
| 11 | + |
| 12 | + return this._super(id, params).then( |
| 13 | + data => Object.assign({ query: params.query }, data) |
| 14 | + ); |
| 15 | + } |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +export default function(callback) { |
| 20 | + const options = { |
| 21 | + transformer: 'websockets' |
| 22 | + }; |
| 23 | + const app = feathers().configure(primus(options, primus => callback(primus))); |
| 24 | + const v1 = feathers().configure(primus(options)).use('/todos', todoService()); |
| 25 | + const v2 = feathers().configure(primus(options)).use('/todos', todoService()); |
| 26 | + |
| 27 | + app.use('/api/v1', v1); |
| 28 | + app.use('/api/v2', v2); |
| 29 | + |
| 30 | + v1.service('todos').create({ text: 'some todo', complete: false }, {}, function() {}); |
| 31 | + v2.service('todos').create({ text: 'some todo', complete: false }, {}, function() {}); |
| 32 | + |
| 33 | + return app; |
| 34 | +} |
0 commit comments