Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. Does not use a socket connection so can be run against an inactive server (server not in listen mode).
const http = require('http')
const inject = require('@foxify/inject').default
const dispatch = function (req, res) {
const reply = 'Hello World'
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length })
res.end(reply)
}
// Nah, you don't need this anymore :)
// const server = http.createServer(dispatch)
inject(dispatch, { method: 'get', url: '/' }, (err, res) => {
console.log(res.body)
})