open-wa/wa-automate-nodejs

ERROR when running behind nginx proxy #1686

the-jojo-jj posted onGitHub

Hi, i've found open-wa runs by direct hit:

> curl --location --request POST 'http://192.168.45.3:7020/sendText' \
--header 'api_key: 744858c547272xxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "args": {
    "to": "4474472xxxxx@c.us",
    "content": "Hello World!”
  }
}'

but, when put behind the nginx reverse proxy with following config:

location /v01/wa/xxxxxxx/ {
        if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
        }
        proxy_redirect off;
        proxy_set_header host $host;
        proxy_set_header X-real-ip $remote_addr;
        proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.45.3:7020/;
        }

i've got:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token <br> in JSON at position 74<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (/root/.npm/_npx/21fe510f43113ad2/node_modules/body-parser/lib/types/json.js:89:19)<br> &nbsp; &nbsp;at /root/.npm/_npx/21fe510f43113ad2/node_modules/body-parser/lib/read.js:121:18<br> &nbsp; &nbsp;at invokeCallback (/root/.npm/_npx/21fe510f43113ad2/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at done (/root/.npm/_npx/21fe510f43113ad2/node_modules/raw-body/index.js:213:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/root/.npm/_npx/21fe510f43113ad2/node_modules/raw-body/index.js:273:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:377:35)<br> &nbsp; &nbsp;at endReadableNT (node:internal/streams/readable:1312:12)<br> &nbsp; &nbsp;at processTicksAndRejections (node:internal/process/task_queues:83:21)</pre>
</body>
</html>

@the-jojo-jj the issue is with how your reverse proxy is breaking the json payload.

not related to this lib.

posted by smashah over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests