diff --git a/src/middlewares/modded.express.mung.js b/src/middlewares/modded.express.mung.ts similarity index 96% rename from src/middlewares/modded.express.mung.js rename to src/middlewares/modded.express.mung.ts index e8459b38..8f65942c 100644 --- a/src/middlewares/modded.express.mung.js +++ b/src/middlewares/modded.express.mung.ts @@ -5,7 +5,7 @@ 'use strict'; -let mung = {}; +let mung: any = {}; let faux_fin = { end: () => null }; function isScalar(v) { @@ -135,7 +135,7 @@ mung.headersAsync = function headersAsync(fn) { return mung.onError(e, req, res, next); }; function headers_async_hook() { - if (res.headersSent) return original.apply(this, args); + if (res.headersSent) return original.apply(this, null); // (this, args) let args = arguments; res.end = () => null; try { @@ -145,9 +145,9 @@ mung.headersAsync = function headersAsync(fn) { if (res.headersSent) return; original.apply(this, args); }) - .catch(e => onError(e, req, res, next)); + .catch(e => onError(e)); } catch (e) { - onError(e, req, res, next); + onError(e); } } res.end = headers_async_hook; @@ -205,4 +205,4 @@ mung.write = function write(fn, options = {}) { }; }; -module.exports = mung; +export default mung; diff --git a/src/middlewares/openapi.response.validator.ts b/src/middlewares/openapi.response.validator.ts index 4b2b1a3e..b8a1cc38 100644 --- a/src/middlewares/openapi.response.validator.ts +++ b/src/middlewares/openapi.response.validator.ts @@ -1,5 +1,6 @@ import ono from 'ono'; import * as Ajv from 'ajv'; +import mung from './modded.express.mung'; import { createResponseAjv } from './ajv'; import { extractContentType, @@ -7,7 +8,6 @@ import { validationError, } from './util'; -const mung = require('./modded.express.mung'); const TYPE_JSON = 'application/json'; export class ResponseValidator { @@ -25,6 +25,7 @@ export class ResponseValidator { } validate() { + console.log('=======', mung); return mung.json((body, req: any, res) => { if (req.openapi) { const responses = req.openapi.schema && req.openapi.schema.responses; diff --git a/tsconfig.json b/tsconfig.json index 17f75919..3a1c4894 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,5 +10,5 @@ }, "exclude": ["node_modules"], - "include": ["typings.d.ts", "src/**/*.ts", "src/middlewares/modded.express.mung.js"] + "include": ["typings.d.ts", "src/**/*.ts", "src/middlewares/modded.express.mung.ts"] }