Included definition for proxyErrorHandler in express-http-proxy (#35185)

This commit is contained in:
Niek van Bennekom
2019-05-03 14:46:25 -07:00
committed by Wesley Wigham
parent 18b13d1f4a
commit 6a3064cc74
2 changed files with 13 additions and 1 deletions
@@ -19,6 +19,16 @@ proxy('www.google.com', {
limit: 1024
});
proxy('www.google.com', {
proxyErrorHandler: (err, res, next) => {
switch (err && err.code) {
case 'ECONNRESET': { return res.status(405).send('504 became 405'); }
case 'ECONNREFUSED': { return res.status(200).send('gotcher back'); }
default: { next(err); }
}
},
});
proxy('www.google.com', {
proxyReqOptDecorator(proxyReqOpts, srcReq) {
console.log(proxyReqOpts.headers, proxyReqOpts.method);
+3 -1
View File
@@ -3,12 +3,13 @@
// Definitions by: ulrichb <https://github.com/ulrichb>
// Daniel Schopf <https://github.com/Danscho>
// Gabriel Fournier <https://github.com/carboneater>
// Niek van Bennekom <https://github.com/niekvb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import { RequestHandler, Request } from "express";
import { RequestOptions, IncomingHttpHeaders, OutgoingHttpHeaders } from "http";
import { Response } from "express-serve-static-core";
import { NextFunction, Response } from "express-serve-static-core";
interface ProxyOptions {
/**
@@ -17,6 +18,7 @@ interface ProxyOptions {
* See https://github.com/stream-utils/raw-body/blob/master/index.d.ts
*/
limit?: number | string;
proxyErrorHandler?: (err: any, res: Response, next: NextFunction) => any;
proxyReqPathResolver?: (req: Request) => string;
proxyReqOptDecorator?: (proxyReqOpts: RequestOptions, srcReq: Request) => RequestOptions;
userResHeaderDecorator?: (headers: IncomingHttpHeaders, userReq: Request, userRes: Response, proxyReq: Request, proxyRes: Response) => OutgoingHttpHeaders;