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

Cannot get any data into any Post method #56

Closed
ldittel opened this issue Dec 21, 2016 · 4 comments
Closed

Cannot get any data into any Post method #56

ldittel opened this issue Dec 21, 2016 · 4 comments

Comments

@ldittel
Copy link

ldittel commented Dec 21, 2016

I have a very simple controller method

@Post("/register") register(@Req() request: any, @Res() response: any) { console.log(JSON.stringify(request.body)); return ""; }

and I'm trying to pass in some post data using the curl CLI iunder windows:

curl -X POST -H "Content-Type: application/json" -d "{ \"email\": \"lergfdl@gmail.com\", \"name\": \"john\", \"password\": \"1\" }" localhost:8080/api/auth/register

Somehow I cannot for the life of me get any of the data to come through i.e. the body is a l w a y s empty.
I have absolutely no idea where the problem is as the @get methods work no problem.

Please advise.
Thansk you so much.

@ldittel
Copy link
Author

ldittel commented Dec 22, 2016

Right, so it turned out to be partially an express.js issue - where the bodyParser needs to be registered in the right order to other middlware e.g. router. I have opted to switch from createExpressServer() to useExpressServer() to have more control of the initialization process. I suspect the createES() method has an issue somewhere.

Anyway, hope it;ll help someone as I was going a little bit mad.

@MichalLytek
Copy link
Contributor

Express 4.x is modular so you need to have eg. body-parser and cookie-parser installed and loaded explicitly by yourself. It's not routing-controllers fault, it's just how the express behave itself, so I think the issue could be closed now.

@ldittel
Copy link
Author

ldittel commented Feb 7, 2017

That is correct. Thanks for the input.

@ldittel ldittel closed this as completed Feb 7, 2017
@github-actions
Copy link

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants