Repository URL to install this package:
|
Version:
5.3.0 ▾
|
import express from 'express'
import {
Request as ExpressRequest,
Response as ExpressResponse,
NextFunction,
} from 'express'
/**
* @michael from @james
* this is what was responding with the data used in the tests
*/
function fromReqResToDebug(req) {
const {
protocol,
path,
hostname,
host,
xhr,
body,
cookies,
method,
params,
query,
route,
signedCookies,
originalUrl,
url,
baseUrl,
locals,
charset,
headersSent,
_header,
headers,
data,
statusCode,
status,
statusText,
} = req
const nonCircular = {
headers,
data,
statusCode,
status,
statusText,
_header,
protocol,
path,
hostname,
host,
xhr,
body,
cookies,
method,
params,
query,
route,
signedCookies,
originalUrl,
url,
baseUrl,
// res
headersSent,
locals,
charset,
}
return nonCircular
}
export const server = {
stop() {
//
},
start() {
return startServer()
},
}
function startServer() {
const app = express()
app.use((req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
// console.log(fromReqResToDebug(req))
res
.status(200)
.json({ hi: 'eh' })
.send()
})
return new Promise(resolve => {
const onListen = () => resolve(listener)
const listener = app.listen(3333, onListen)
server.stop = () => listener.close()
})
}