UNPKG

@paroicms/server

Version:
48 lines 1.36 kB
import { Stream } from "node:stream"; export function toPaHttpContext(expressReq, expressRes) { const req = { hostname: expressReq.hostname, headers: expressReq.headers, method: expressReq.method, relativeUrl: expressReq.url, path: expressReq.path, query: expressReq.query, body: expressReq.body, file: expressReq.file, cookies: expressReq.cookies, }; let headersSent = false; const res = { get headersSent() { return headersSent || expressRes.headersSent; }, status(code) { expressRes.status(code); return res; }, append(field, value) { expressRes.append(field, value); return res; }, send(body) { headersSent = true; if (body instanceof Stream) { body.pipe(expressRes); } else { expressRes.send(body); } return res; }, cookie(name, value, options) { expressRes.cookie(name, value, options); return res; }, clearCookie(name, options) { expressRes.clearCookie(name, options); return res; }, }; return { req, res }; } //# sourceMappingURL=pa-http-context.js.map