8000 Add _setup method by daffl · Pull Request #91 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

Add _setup method#91

Merged
daffl merged 1 commit intomasterfrom
rest-conflicting-routes-86
Aug 11, 2014
Merged

Add _setup method#91
daffl merged 1 commit intomasterfrom
rest-conflicting-routes-86

Conversation

@daffl
Copy link
Member
@daffl daffl commented Aug 10, 2014

This pull request adds a service._setup(app, path) method that allows registering conflicting routes as reported in and closes #86. Works as described in the documentation added:

setup will be called after all REST routes have been set up. This means that you
can't register custom middleware with potentially conflicting paths.
In this case, implement _setup(app, path) instead which will run before the REST
middleware is registered. An example would be implementing a todos/count route
which returns the number of todos (instead of the todo with the id count):

var todoService = {
  todos: [
    {
      id: 0,
      description: 'Learn Feathers'
    },
    {
      id: 1,
      description: 'Do dishes'
    }
  ],

  find: function (params, callback) {
    callback(null, this.todos);
  },

  _setup: function (app, path) {
    var self = this;

    app.get('/' + path + '/count', function (req, res) {
      self.find({}, function (error, todos) {
        res.json({
          count: todos.length
        });
      });
    });
  }
};

feathers()
  .use('todos', todoService)
  .listen(8000);

@daffl daffl added this to the 1.0.0 milestone Aug 10, 2014
daffl added a commit that referenced this pull request Aug 11, 2014
@daffl daffl merged commit d01999b into master Aug 11, 2014
@daffl daffl deleted the rest-conflicting-routes-86 branch August 11, 2014 16:35
@elixiao
Copy link
elixiao commented May 2, 2017

can I get "params" or "params.query" in custom service methods?

@daffl
Copy link
Member Author
daffl commented May 3, 2017

@elixiao Yes, you always do in any service if you call it through REST or websockets. You will have to pass query yourself on the server.

daffl added a commit that referenced this pull request Aug 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding custom method to service

2 participants

0