nanoexpress / legacy

[Deprecated] Nano-framework for Node.js. Use PRO version
https://nanoexpress.js.org
Apache License 2.0
107 stars 13 forks source link

JSON body #82

Closed literakl closed 4 years ago

literakl commented 4 years ago

Version 1.1.8

URL encoded www form data:

{"email":"literak@seznam.cz","password":"centrum"}:

    console.log(req);

body: [Object: null prototype] { '{"email":"literak@seznam.cz","password":"centrum"}': '' }

Nanoexpress thinks that this is a key with empty value.

so this fails:

    const { email, password } = req.body;
dalisoft commented 4 years ago

Try latest version, should work. I fixed, seems still not working properly .

Can you explain bit more?

dalisoft commented 4 years ago

I running body-parser example locally with some logging.

Example.

  1. It works as expected including destructuring.
  2. [Object: null prototype] - it's OK, but for now at least, this happens due of querystring parse function which does with Object something, but it's works same as `Object.

Try re-run or create minimal reproducible repository to debug.

Thanks for reporting bugs

literakl commented 4 years ago

JSON application type is parsed correctly, when I send the request from Postman, so you can close this issue. But I am stuck with frontend https://stackoverflow.com/questions/60763165/axios-post-stalled-in-chrome.

literakl commented 4 years ago

It is CORS issue. How can I write OPTIONS handler with empty body? I tried this, but it did not help for chrome and it does not return anything to Postman until time out.

app.options('/v1/authorizeUser', async (req, res) => { console.log("OPTIONS authorizeUser"); res.status(200); res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); return res; });