Skip to content

Using stream with router #53

Open
Open
@morriq

Description

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)
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions