-
Notifications
You must be signed in to change notification settings - Fork 415
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
1.0.0-pre2 - this.request.body undefined :( #842
Comments
Same issue here, even when using the new syntax: http://eventedmind.github.io/iron-router/#server-routing |
It's because node deals with the http body as a stream which is confusing. You can use the bodyParser to solve this problem. On the server: Router.use(Router.bodyParser.json()) For example. Don't forget to set the content-type header in the request. Ie content-type: 'application/json'
|
but our code used to work fine with iron-router 0.9.x ?? |
I might have added that connect middleware automatically in the last version. I need to check. Perhaps it's worth adding it automatically again. Google search for examples of bodyParser for more details - it's connect middleware. I attached it to Router so you don't have to worry about including that npm package in your projects.
|
@cmather I agree, adding it automatically would be great :) |
Will the old behavior come back with the coming release ? |
Router.use(Router.bodyParser()); causes the following output:
|
See also #909 |
@cmather - I'm guessing you are not planning on doing this automatically? Close if so. @boustanihani - you needed to add |
In the next release json parsing is done automatically. If you need a custom body parser you'll need to add it yourself. See the example in global_router.js |
Suggestion: Why not also add urlencoded & text automatically ?? Router.onBeforeAction(Iron.Router.bodyParser.urlencoded( {extended : false} ));
Router.onBeforeAction(Iron.Router.bodyParser.text()); |
Hi,
Me again, sorry.
I am trying to put together an API on the server, where you could POST JSON object. Used to work fine, but now I can't have access to
this.request.body
it'sundefined
.Here is my code
If that comes from iron-router you might be already aware of this.
Maybe I should stick with the latest stable version instead of breaking things 😄
Thanks
The text was updated successfully, but these errors were encountered: