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

Parsing json hangs #41

Open
snewell92 opened this issue Oct 4, 2017 · 14 comments

Comments

@snewell92
Copy link

commented Oct 4, 2017

I had been using micro perfectly fine locally, but then decided to use micro-dev for local development, but it won't parse the json body of my requests anymore :\ I'm sending the requests via postman. Not sure what's different or if I missed something in the docs/setup. (I didn't change source code at all).

Gist of code

The important part of my gist is index.ts, and the function waitForEmail line 75

Versions
Node: 8.4.0 and 8.5.0
NPM: 5.3.0 and 5.4.2
OS: WIndows 10 Pro and Ubuntu (WSL); both 64bit

(package.json given in gist, shows latest versions of micro and micro-dev).

Thanks for reading!

@maccyber

This comment has been minimized.

Copy link

commented Oct 24, 2017

I have the same issue.
Parsing buffer, text or json causes micro-dev to hang.

The problem lies in log.js - reqBodyReady needs to be set after res.end

const reqBodyReady = logRequest({ req, start, requestIndex })

@floatdrop

This comment has been minimized.

Copy link
Contributor

commented Oct 24, 2017

@maccyber I think the real problem here is that logRequest does not share same request body cache with loaded micro instance.

@maccyber

This comment has been minimized.

Copy link

commented Oct 24, 2017

Ah, that may be @floatdrop

Example with router and express-jwt

const {send, json} = require('micro')
const Router = require('router')
const finalhandler = require('finalhandler')
const jwt = require('express-jwt')
const router = Router()

const test = async (req, res) => {
  try {
    const payload = await json(req)
    send(res, 200, payload)
  } catch (error) {
    send(res, 500, error)
  }
}

router.use(jwt({secret: 'abc123'}))
router.post('/', test)

module.exports = (req, res) => {
  router(req, res, finalhandler(req, res))
}

Request

curl -i -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.9anRBxf5MRx0vhC4oUlZoVlqL7IZBBvuEfcAJP1VUtI"  -d '{"test":1}' http://localhost:3000/
@varna

This comment has been minimized.

Copy link

commented Nov 7, 2017

await json(req) hangs for me too.

@NetOperatorWibby

This comment has been minimized.

Copy link

commented Jan 21, 2018

Has this been fixed? Anyone have a solution?

@mingxhzhu

This comment has been minimized.

Copy link

commented Mar 12, 2018

Still having the same problem.

@whoisteri

This comment has been minimized.

Copy link

commented May 14, 2018

This still hasn't been fixed and I'm kind of stuck on it. :(

@ezequieltejada

This comment has been minimized.

Copy link

commented May 28, 2018

Same for me

@varna

This comment has been minimized.

Copy link

commented Aug 30, 2018

I just stumbled upon the same problem again. Is micro dying? 🗡

@mingxhzhu

This comment has been minimized.

Copy link

commented Aug 30, 2018

looks like it is.

@NetOperatorWibby

This comment has been minimized.

Copy link

commented Aug 30, 2018

Time for a fork!

@jamo

This comment has been minimized.

Copy link

commented Aug 30, 2018

Pull requests are welcome btw 🤞

@NetOperatorWibby

This comment has been minimized.

Copy link

commented Aug 30, 2018

There are a couple PRs with no comments or indication that they'll be merged. Where's the incentive?

@ferdinandsalis

This comment has been minimized.

Copy link

commented Jun 25, 2019

Any plans on tending to this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.