Skip to content

Commit

Permalink
mod mung
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Sep 18, 2019
1 parent daba1a2 commit 1419437
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -5,7 +5,7 @@

'use strict';

let mung = {};
let mung: any = {};
let faux_fin = { end: () => null };

function isScalar(v) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -205,4 +205,4 @@ mung.write = function write(fn, options = {}) {
};
};

module.exports = mung;
export default mung;
3 changes: 2 additions & 1 deletion src/middlewares/openapi.response.validator.ts
@@ -1,13 +1,13 @@
import ono from 'ono';
import * as Ajv from 'ajv';
import mung from './modded.express.mung';
import { createResponseAjv } from './ajv';
import {
extractContentType,
ajvErrorsToValidatorError,
validationError,
} from './util';

const mung = require('./modded.express.mung');
const TYPE_JSON = 'application/json';

export class ResponseValidator {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -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"]
}

0 comments on commit 1419437

Please sign in to comment.