Parsing json hangs
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!
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
@maccyber I think the real problem here is that logRequest does not share same request body cache with loaded micro instance.
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/
await json(req) hangs for me too.
Has this been fixed? Anyone have a solution?
Still having the same problem.
This still hasn't been fixed and I'm kind of stuck on it. :(
Same for me
I just stumbled upon the same problem again. Is micro dying? 🗡
looks like it is.
Time for a fork!
Pull requests are welcome btw 🤞
There are a couple PRs with no comments or indication that they'll be merged. Where's the incentive?
Any plans on tending to this issue?
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.