Skip to content

Commit

Permalink
refactor!: new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Jul 6, 2024
1 parent dc20cfa commit 70739d3
Show file tree
Hide file tree
Showing 14 changed files with 1,894 additions and 2,822 deletions.
7 changes: 4 additions & 3 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const path = require('node:path')

const indexPath = path.join(__dirname, 'index.html')

const server = http.createServer(function onRequest (req, res) {
send(req, indexPath)
.pipe(res)
const server = http.createServer(async function onRequest (req, res) {
const { statusCode, headers, stream } = await send(req, indexPath)
res.writeHead(statusCode, headers)
stream.pipe(res)
})

server.listen(3000)
17 changes: 1 addition & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@
*/
const isUtf8MimeType = require('./lib/isUtf8MimeType').isUtf8MimeType
const mime = require('mime')
const SendStream = require('./lib/SendStream')

/**
* Return a `SendStream` for `req` and `path`.
*
* @param {object} req
* @param {string} path
* @param {object} [options]
* @return {SendStream}
* @public
*/

function send (req, path, options) {
return new SendStream(req, path, options)
}
const send = require('./lib/send').send

/**
* Module exports.
Expand All @@ -37,7 +23,6 @@ function send (req, path, options) {
module.exports = send
module.exports.default = send
module.exports.send = send
module.exports.SendStream = SendStream

module.exports.isUtf8MimeType = isUtf8MimeType
module.exports.mime = mime
Loading

0 comments on commit 70739d3

Please sign in to comment.