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

Using stream with router #53

Open
morriq opened this issue Sep 14, 2018 · 1 comment
Open

Using stream with router #53

morriq opened this issue Sep 14, 2018 · 1 comment

Comments

@morriq
Copy link

morriq commented Sep 14, 2018

Hello, I think it might be issue, please check this out:

this code below don't return any response from the server. neither error too.

const fs = require('fs')
const { router, get } = require('microrouter')


const bundle = (req, res) => {
	res.statusCode = 200
	const obj = fs.createReadStream('./dist/bundle.js')

	res.setHeader('Content-Type', 'application/javascript')

	obj.pipe(res)
}

module.exports = router(
	get('/', bundle)
)

The same arrow function will work without router functionality:

const fs = require('fs')


module.exports = (req, res) => {
	res.statusCode = 200
	const obj = fs.createReadStream('./dist/bundle.js')

	res.setHeader('Content-Type', 'application/javascript')

	obj.pipe(res)
}
@shawninder
Copy link

I get a similar result with:

const response = await fetch(...)
response.body.pipe(res)

On the receiving end I just get a 204 with no content, yet fetch does respond with data

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

No branches or pull requests

2 participants