UNPKG

@n1k1t/mock-server

Version:

Powerful util to setup mocks over HTTP APIs

35 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InternalHttpRequestContext = void 0; const models_1 = require("../../../models"); const reply_1 = require("./reply"); const logger_1 = require("../../../../logger"); const logger = logger_1.Logger.build('Server.Transports.Internal.Http.Context'); class InternalHttpRequestContext extends models_1.RequestContext { constructor(server, incoming, request, response) { super(server.providers.default, { transport: 'http', event: 'connection' }); this.server = server; this.incoming = incoming; this.request = request; this.response = response; this.snapshot = this.compileSnapshot(); this.reply = reply_1.InternalHttpReply.build(this); logger.info('Incoming request', `[${incoming.method} ${incoming.path}]`); } complete() { logger.info(`Incoming request [${this.incoming.method} ${this.incoming.path}] has finished`, `with status [${this.outgoing?.status ?? 200}] in [${Date.now() - this.timestamp}ms]`); return super.complete(); } compileHistory() { return models_1.History.build({ group: this.provider.group, snapshot: this.compileSnapshot().assign({ messages: [] }), }); } static async build(server, request, response) { const incoming = await (0, models_1.extractHttpIncommingContext)(request); return new InternalHttpRequestContext(server, incoming, request, response); } } exports.InternalHttpRequestContext = InternalHttpRequestContext; //# sourceMappingURL=context.js.map