Ad

POST Params Are Not Passes From My Reverse Proxy To My Backend Server

I have a nginx server which provides static web content and a reverse proxy which exchange with my backend API. I configured with certbot my SSL certificate. My problem is that the POST params are not passed from my reverse-proxy t my backend server. My GET params are retrieved properly.

I've logged my POST request in Nginx "POST /Users/signup HTTP/2.0" 500 1181 "https://MYDNS/signup" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" [{\x22username\x22:\x22testet\x22}]

My nginx configuration file

    server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
        server_name MYDNS;
    root /var/www/MYDNS;

    ssl_certificate /etc/letsencrypt/live/MYDNS/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/MYDNS/privkey.pem;

    error_log /var/log/nginx/MYDNS.error.log warn;
    access_log  /var/log/nginx/MYDNS.postdata-access.log post_logs; 

     location /Users {
            proxy_pass http://127.0.0.1:3001;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }

    server {
    listen 80;
    listen [::]:80;

    server_name MYDNS;

    return 301 https://MYDNS$request_uri;
    }

In my backend server in my app.js file

     var Users =require('./routes/Users');
     app.use('/Users',Users);

In my routes/Users.js file

     router.post('/signin', function (req, res, next) {
     console.log(req.params.username); --> undefined
     console.log(req.body.username); --> undefined
     });

I also tried to change proxy_pass http://127.0.0.1:3001 to proxy_pass http://localhost:3001

On my server, I've tested

    curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"username": "this_is_param_1"}' http://localhost:3001/Users/signin

but the result is the same. Any idea please ?

Ad

Answer

I've made a mistake and disable bodyParser in my backend server It's OK now

Ad
source: stackoverflow.com
Ad