@opra/nestjs-http
Version:
Opra NestJS Http Module
31 lines (30 loc) • 1.04 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { Injectable } from '@nestjs/common';
import { HttpContext, HttpIncoming, HttpOutgoing } from '@opra/http';
import { OpraHttpNestjsAdapter } from './opra-http-nestjs-adapter.js';
let OpraMiddleware = class OpraMiddleware {
constructor(opraAdapter) {
this.opraAdapter = opraAdapter;
}
use(req, res, next) {
const request = HttpIncoming.from(req);
const response = HttpOutgoing.from(res);
/** Create the HttpContext */
const context = new HttpContext({
adapter: this.opraAdapter,
platform: req.route ? 'express' : 'fastify',
request,
response,
});
req.opraContext = context;
this.opraAdapter
.emitAsync('createContext', context)
.then(() => next())
.catch(next);
}
};
OpraMiddleware = __decorate([
Injectable(),
__metadata("design:paramtypes", [OpraHttpNestjsAdapter])
], OpraMiddleware);
export { OpraMiddleware };