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 · 15 comments
Open

Parsing json hangs #41

snewell92 opened this issue Oct 4, 2017 · 15 comments

Comments

@snewell92
Copy link

@snewell92 snewell92 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
Copy link

@maccyber maccyber 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

https://github.com/zeit/micro-dev/blob/11e501734daf2f02896321d2321e1e03a8b752ad/lib/log.js#L97

Loading

@floatdrop
Copy link
Contributor

@floatdrop floatdrop 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.

Loading

@maccyber
Copy link

@maccyber maccyber 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/

Loading

@varna
Copy link

@varna varna commented Nov 7, 2017

await json(req) hangs for me too.

Loading

@NetOpWibby
Copy link

@NetOpWibby NetOpWibby commented Jan 21, 2018

Has this been fixed? Anyone have a solution?

Loading

@lilonpro
Copy link

@lilonpro lilonpro commented Mar 12, 2018

Still having the same problem.

Loading

@kdojeteri
Copy link

@kdojeteri kdojeteri commented May 14, 2018

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

Loading

@ezequieltejada
Copy link

@ezequieltejada ezequieltejada commented May 28, 2018

Same for me

Loading

@varna
Copy link

@varna varna commented Aug 30, 2018

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

Loading

@lilonpro
Copy link

@lilonpro lilonpro commented Aug 30, 2018

looks like it is.

Loading

@NetOpWibby
Copy link

@NetOpWibby NetOpWibby commented Aug 30, 2018

Time for a fork!

Loading

@jamo
Copy link

@jamo jamo commented Aug 30, 2018

Pull requests are welcome btw 🤞

Loading

@NetOpWibby
Copy link

@NetOpWibby NetOpWibby commented Aug 30, 2018

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

Loading

@ferdinandsalis
Copy link

@ferdinandsalis ferdinandsalis commented Jun 25, 2019

Any plans on tending to this issue?

Loading

@cchiaramelli
Copy link

@cchiaramelli cchiaramelli commented Jun 4, 2020

I think the simpliest turnaround would be not use micro-dev as global dependency. Just install it as devDependency on the project and add a script.

$ npm install --save-dev micro-dev

// package.json
{
  "scripts": {
    "dev": "micro-dev index.js"
  }
}

$ npm run dev

The definitive solution doesn't look simple since it would be needed to read request stream twice, or clone it somehow.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet