Skip to content

Instantly share code, notes, and snippets.

@garthk
Created December 17, 2018 23:59
Show Gist options
  • Save garthk/77e0a76f0b88bbd51deac180a65debd7 to your computer and use it in GitHub Desktop.
Save garthk/77e0a76f0b88bbd51deac180a65debd7 to your computer and use it in GitHub Desktop.
Quick and dirty typings for h2o2 version 8.1
import { BoomError } from 'boom';
import { Request, HandlerDecorations, ResponseToolkit } from 'hapi';
import { Agent, IncomingMessage } from 'http';
import { Server, PluginPackage } from 'hapi';
import { ResponseObject } from 'hapi';
export interface ProxyHandlerOptions {
host?: string;
port?: number | string;
protocol?: 'http' | 'https';
uri?: string;
passThrough?: boolean;
localStatePassThrough?: boolean;
acceptEncoding?: boolean;
rejectUnauthorized?: boolean;
xforward?: boolean;
redirects?: number | false;
timeout?: number;
mapUri?: (this: ProxyHandlerOptions, request: Request) => Promise<{
uri: string;
headers?: { [key: string]: string };
}>;
onResponse?: (this: RouteOptions,
err: null | BoomError,
res: IncomingMessage,
req: Request,
h: ResponseToolkit,
settings: ProxyHandlerOptions,
ttl: number) => ResponseObject;
ttl?: 'upstream';
agent?: Agent;
maxSockets?: false | number;
}
/**
* `h2o2` extensions for the `'hapi'` package.
*/
declare module 'hapi' {
interface HandlerDecorations {
proxy?: ProxyHandlerOptions;
}
interface ResponseToolkit {
proxy(options: ProxyHandlerOptions): ResponseObject;
}
}
declare module 'h2o2' {
function register(server: Server, options?: {}): Promise<void>;
const pkg: PluginPackage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment