Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Routes #670

Closed
muvhaus-sl opened this issue Sep 13, 2017 · 6 comments · Fixed by #697
Closed

Nested Routes #670

muvhaus-sl opened this issue Sep 13, 2017 · 6 comments · Fixed by #697

Comments

@muvhaus-sl
Copy link

Hi,
I have 2 services, Users and Addresses. I tried doing the Nested route example as in:
https://docs.feathersjs.com/faq/readme.html#how-do-i-do-nested-or-custom-routes

this results in:
/users/:userId/addresses

When a Users has only 1 address, it works. When the user has multiple addresses, I receive an error:
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

However, if I do:
/addresses/?userID=xxxx
It works as expected for both single and multiple addresses.

All services are using sequelize/mysql.
I'm using:
"body-parser": "^1.17.2",
"compression": "^1.7.0",
"cors": "^2.8.4",
"feathers": "^2.1.7",
"feathers-authentication": "^1.2.7",
"feathers-authentication-hooks": "^0.1.4",
"feathers-authentication-jwt": "^0.3.2",
"feathers-authentication-local": "^0.4.3",
"feathers-configuration": "^0.4.1",
"feathers-errors": "^2.9.1",
"feathers-hooks": "^2.0.2",
"feathers-hooks-common": "^3.6.1",
"feathers-rest": "^1.8.0",
"feathers-sequelize": "^2.2.0",
"feathers-socketio": "^2.0.0",
"feathers-swagger": "^0.5.0",
"helmet": "^3.8.1",
"mysql2": "^1.4.0",
"sequelize": "^4.4.2",
"serve-favicon": "^2.4.3",
"skypager-service": "^5.4.0",
"winston": "^2.3.1"

@muvhaus-sl
Copy link
Author

A little bit more information. I tried to setup exactly the same structure, for a different service, and it turns out to fail irrespective of the expected result (arrays or single items).
Then I set the DEBUG flag and I got this output any time I hit the nested routes:

  • feathers:rest REST handler calling find from /users/123/addresses
  • info: after: users/:userId/addresses - Method: find
  • feathers-errors NotFound(404): Page not found
  • feathers-errors {}
  • Error: Can't set headers after they are sent.

Even when I call /users/123/addresses and it does return a single addrress, the log still shows the same header error.

Any ideas on what is possibly wrong with the nested routing?

Thank you in advance.

@daffl
Copy link
Member

daffl commented Sep 14, 2017

Does it work if you do something like:

app.use('/users/:userId/addresses', {
  find(params) {
    return this.app.service('addresses').find({
      query: Object.assign({
        userId: params.userId
      }, params.query);
    });
  },

  setup(app) {
    this.app = app;
  }  
});

?

@muvhaus-sl
Copy link
Author

Hi,
It works as expected when using the code above, except for an extra ";" after "params.query)". Is there something wrong on the code provided on the FAQ, or on my overall setup?

@daffl
Copy link
Member

daffl commented Sep 14, 2017

I don't think it's your setup. I'm pretty sure it's related to #566 which will be fixed in the next version but causes some strange issues like yours at the moment.

@muvhaus-sl
Copy link
Author

Ok, so for the time being, the correct solution is to implement nested routes as you pointed me out.

I tried it on a different service, and it worked as well.

My only question would be related to the other methods (create, patch,update), would I just implement like you did for the find?

Thank you for your help.

@lock
Copy link

lock bot commented Feb 7, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants