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

restify 5.0.0 bodyParser() not work #1394

Closed
pangff opened this issue Jul 3, 2017 · 9 comments
Closed

restify 5.0.0 bodyParser() not work #1394

pangff opened this issue Jul 3, 2017 · 9 comments

Comments

@pangff
Copy link

pangff commented Jul 3, 2017

Bug Report

I make a post request to restify server 5.0.0 . but cannot get body params in req.params

Restify Version

  • restify 5.0.0
  • node v8.0.0

Expected behaviour

with code blow:

const restify = require('restify');
const server = restify.createServer({
name: 'video-monitor-service',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());

server.post('/scene/video/report', function(req, res, next){
console.log(req.params)
});

server.listen(3600, function() {
console.log('%s listening at %s', server.name, server.url);
});

and make curl post request as blow:

curl -X POST --data "data=xxx" http://localhost:3600/scene/video/report

I Expected get

{data:xxx}

Actual behaviour

I get req.parms an empty obj

{}

something wrong with my code? and is a bug with restify 5.0.0

@wooiliang
Copy link

wooiliang commented Jul 3, 2017

+1 It happens to me as well. Revert back to 4.3.1 for now.

@igalep
Copy link

igalep commented Jul 3, 2017

+1 , got the same error
went back to 4.3.0

@jgliner
Copy link

jgliner commented Jul 3, 2017

Looks like it's been deprecated...
https://github.com/restify/node-restify/blob/5.x/4TO5GUIDE.md

To re-enable, change server.use(restify.bodyParser()); to server.use(restify.plugins.bodyParser()); per this doc

They should draw more attention to this in their README.md. v5.0.0 breaks quite a few things.

@wooiliang
Copy link

It works, thank you @jgliner !

server.use(restify.plugins.queryParser({
    mapParams: true
}));
server.use(restify.plugins.bodyParser({
    mapParams: true
}));

@pangff
Copy link
Author

pangff commented Jul 4, 2017

It works, thank you @jgliner !

@pangff pangff closed this as completed Jul 4, 2017
@kaiservonarctic
Copy link

That's all it took. Thanks @jgliner!!

@rsathishr
Copy link

d0542c9ec210204c7c0126b614d01335c06f3ba345d1cb7f64 pimgpsh_thumbnail_win_distr

Change the NODE-PATH

@rsathishr
Copy link

image

@kozo002
Copy link

kozo002 commented Jun 29, 2018

@jgliner thanks. you save my time

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

No branches or pull requests

7 participants