mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added missing types in express-http-proxy (#36001)
* Added missing types in express-http-proxy * Fixed comparison * Fixed typo in name
This commit is contained in:
parent
f294b49f63
commit
8d217f3687
@ -3,49 +3,55 @@ import proxy = require("express-http-proxy");
|
||||
|
||||
const app: Express = {} as any;
|
||||
|
||||
app.use('/proxy', proxy('www.google.com'));
|
||||
app.use("/proxy", proxy("www.google.com"));
|
||||
|
||||
proxy('www.google.com', {});
|
||||
proxy("www.google.com", {});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxyReqPathResolver: (req) => req.url,
|
||||
proxy("www.google.com", {
|
||||
proxyReqPathResolver: req => req.url
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
limit: "10mb"
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
limit: 1024
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
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); }
|
||||
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', {
|
||||
proxy("www.google.com", {
|
||||
proxyReqOptDecorator(proxyReqOpts, srcReq) {
|
||||
console.log(proxyReqOpts.headers, proxyReqOpts.method);
|
||||
console.log(srcReq.url, srcReq.cookies);
|
||||
return proxyReqOpts;
|
||||
},
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(proxyReqOpts);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(proxyReqOpts);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
proxy("www.google.com", {
|
||||
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
|
||||
console.log(userReq.url, userRes.statusCode);
|
||||
console.log(proxyReq.url, proxyRes.statusCode);
|
||||
@ -56,7 +62,7 @@ proxy('www.google.com', {
|
||||
}
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
userResDecorator(proxyRes, proxyResData, userReq, userRes) {
|
||||
console.log(userReq.url, userRes.statusCode);
|
||||
const data = JSON.parse(proxyResData.toString("utf8"));
|
||||
@ -65,28 +71,60 @@ proxy('www.google.com', {
|
||||
}
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
userResDecorator(proxyRes, proxyResData, userReq, userRes) {
|
||||
// some code
|
||||
return proxyResData;
|
||||
}
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
userResDecorator(proxyRes, proxyResData, userReq, userRes) {
|
||||
// some code
|
||||
return Promise.resolve(proxyResData);
|
||||
}
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
preserveHostHdr: true
|
||||
});
|
||||
|
||||
proxy('www.google.com', {
|
||||
proxy("www.google.com", {
|
||||
parseReqBody: true
|
||||
});
|
||||
|
||||
const proxyOptions: proxy.ProxyOptions = {};
|
||||
|
||||
app.use('/proxy/:port', proxy((req) => 'localhost:' + req.params.port));
|
||||
app.use("/proxy/:port", proxy(req => "localhost:" + req.params.port));
|
||||
|
||||
proxy("www.google.com", {
|
||||
filter: (req, res) => {
|
||||
return req.method === "GET";
|
||||
}
|
||||
});
|
||||
|
||||
proxy("www.google.com", {
|
||||
memoizeHost: true
|
||||
});
|
||||
|
||||
proxy("www.google.com", {
|
||||
skipToNextHandlerFilter: proxyRes => {
|
||||
return proxyRes.statusCode === 404;
|
||||
}
|
||||
});
|
||||
|
||||
proxy("www.google.com", {
|
||||
https: true
|
||||
});
|
||||
|
||||
proxy("www.google.com", {
|
||||
reqAsBuffer: true
|
||||
});
|
||||
|
||||
proxy("httpbin.org", {
|
||||
reqBodyEncoding: null
|
||||
});
|
||||
|
||||
proxy("httpbin.org", {
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
39
types/express-http-proxy/index.d.ts
vendored
39
types/express-http-proxy/index.d.ts
vendored
@ -5,6 +5,7 @@
|
||||
// Gabriel Fournier <https://github.com/carboneater>
|
||||
// Niek van Bennekom <https://github.com/niekvb>
|
||||
// John L. Singleton <https://github.com/jsinglet>
|
||||
// Lindsay Wardell <https://github.com/lindsaykwardell>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
@ -19,16 +20,44 @@ declare namespace proxy {
|
||||
* See https://github.com/stream-utils/raw-body/blob/master/index.d.ts
|
||||
*/
|
||||
limit?: number | string;
|
||||
proxyErrorHandler?: (err: any, res: Response, next: NextFunction) => any;
|
||||
proxyErrorHandler?: (
|
||||
err: any,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => any;
|
||||
proxyReqPathResolver?: (req: Request) => string;
|
||||
proxyReqOptDecorator?: (proxyReqOpts: RequestOptions, srcReq: Request) => RequestOptions | Promise<RequestOptions>;
|
||||
userResHeaderDecorator?: (headers: IncomingHttpHeaders, userReq: Request, userRes: Response, proxyReq: Request, proxyRes: Response) => OutgoingHttpHeaders;
|
||||
userResDecorator?: (proxyRes: Response, proxyResData: any, userReq: Request, userRes: Response) => Buffer | string | Promise<Buffer|string>;
|
||||
proxyReqOptDecorator?: (
|
||||
proxyReqOpts: RequestOptions,
|
||||
srcReq: Request
|
||||
) => RequestOptions | Promise<RequestOptions>;
|
||||
userResHeaderDecorator?: (
|
||||
headers: IncomingHttpHeaders,
|
||||
userReq: Request,
|
||||
userRes: Response,
|
||||
proxyReq: Request,
|
||||
proxyRes: Response
|
||||
) => OutgoingHttpHeaders;
|
||||
userResDecorator?: (
|
||||
proxyRes: Response,
|
||||
proxyResData: any,
|
||||
userReq: Request,
|
||||
userRes: Response
|
||||
) => Buffer | string | Promise<Buffer | string>;
|
||||
preserveHostHdr?: boolean;
|
||||
parseReqBody?: boolean;
|
||||
filter?: (req: Request, res: Response) => boolean;
|
||||
memoizeHost?: boolean;
|
||||
skipToNextHandlerFilter?: (proxyRes: Response) => boolean;
|
||||
https?: boolean;
|
||||
reqAsBuffer?: boolean;
|
||||
reqBodyEncoding?: string | null;
|
||||
timeout?: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare function proxy(host: string|((req: Request) => string), options?: proxy.ProxyOptions): RequestHandler;
|
||||
declare function proxy(
|
||||
host: string | ((req: Request) => string),
|
||||
options?: proxy.ProxyOptions
|
||||
): RequestHandler;
|
||||
|
||||
export = proxy;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user