h2o2: fix response toolkit decoration

`h.proxy` returns a `Promise<ResponseObject>`, not `undefined`.
This commit is contained in:
Garth Kidd
2019-01-08 16:18:46 +11:00
parent 35b53956c7
commit a930d7bc3a
2 changed files with 20 additions and 4 deletions
+12
View File
@@ -140,6 +140,18 @@ const badProtocolDemo: hapi.ServerRoute = {
}
};
const replyViaToolkit: hapi.ServerRoute = {
method: 'GET',
path: '/',
async handler(req, h): Promise<hapi.ResponseObject> {
return h.proxy({
host: '10.33.33.1',
port: '443',
protocol: 'https'
});
}
};
if (!module.parent) {
main().then(() => console.log('done'), err => console.error(err.stack));
}
+8 -4
View File
@@ -1,6 +1,6 @@
// Type definitions for h2o2 8.1
// Project: https://github.com/hapijs/h2o2
// Definitions by: Jason Swearingen <https://github.com/jasonswearingen>, AJP <https://github.com/AJamesPhillips>
// Definitions by: Jason Swearingen <https://github.com/jasonswearingen>, AJP <https://github.com/AJamesPhillips>, Garth Kidd <https://github.com/garthk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -83,13 +83,17 @@ declare namespace h2o2 {
declare module 'hapi' {
interface HandlerDecorations {
/** Proxies the request to an upstream endpoint */
/**
* Proxies the request to an upstream endpoint.
*/
proxy?: h2o2.ProxyHandlerOptions;
}
interface ResponseToolkit {
/** Proxies the request to an upstream endpoint */
proxy(options: h2o2.ProxyHandlerOptions): void;
/**
* Proxies the request to an upstream endpoint. `async`, so you'll need to `await` the `ResponseObject` to work on it before returning it.
*/
proxy(options: h2o2.ProxyHandlerOptions): Promise<ResponseObject>;
}
}