diff --git a/types/hapi/v17/test/index.test.d.ts b/types/hapi/v17/test/index.test.d.ts index 35555aa057..fb3babbbec 100644 --- a/types/hapi/v17/test/index.test.d.ts +++ b/types/hapi/v17/test/index.test.d.ts @@ -19,6 +19,8 @@ export * from './reply/reply'; export * from './reply/state_cookie'; export * from './request/event-types'; +export * from './request/get-log'; +export * from './request/query'; export * from './response/error'; diff --git a/types/hapi/v17/test/reply/state_cookie.ts b/types/hapi/v17/test/reply/state_cookie.ts index 4ef420915e..9952ee0e77 100644 --- a/types/hapi/v17/test/reply/state_cookie.ts +++ b/types/hapi/v17/test/reply/state_cookie.ts @@ -1,7 +1,6 @@ // from https://hapijs.com/tutorials/cookies?lang=en_US import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute, ServerStateCookieOptions} from "hapi"; - const options: ServerOptions = { port: 8000, }; diff --git a/types/hapi/v17/test/request/get-log.ts b/types/hapi/v17/test/request/get-log.ts new file mode 100644 index 0000000000..89084cbb07 --- /dev/null +++ b/types/hapi/v17/test/request/get-log.ts @@ -0,0 +1,30 @@ +// From https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data +import {Lifecycle, Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi"; + +const options: ServerOptions = { + port: 8000, +}; + +const handler: Lifecycle.Method = function(request: Request, h: ResponseToolkit) { + request.log(['test', 'error'], 'Test event'); + return 'path: ' + request.path; +}; + +const serverRoute: ServerRoute = { + path: '/', + method: 'GET', + handler: handler +}; + +const server = new Server(options); +server.route(serverRoute); +server.start(); +console.log('Server started at: ' + server.info.uri); + +server.events.on('request', (request: Request, event: any, tags: any) => { + console.log(event); + console.log(tags); + if (tags.error) { + console.log(event); + } +}); diff --git a/types/hapi/v17/test/request/query.ts b/types/hapi/v17/test/request/query.ts new file mode 100644 index 0000000000..e176e078e9 --- /dev/null +++ b/types/hapi/v17/test/request/query.ts @@ -0,0 +1,27 @@ +// Added test in addition to docs, for request.query +import {Request, ResponseToolkit, Lifecycle, Server, ServerOptions, ServerRoute} from "hapi"; + +const options: ServerOptions = { + port: 8000, +}; + +const handler: Lifecycle.Method = function(request: Request, h: ResponseToolkit) { + const query = request.query as GetThingQuery; + // http://localhost:8000/?name=test + return `You asked for ${query.name}` +}; + +const serverRoute: ServerRoute = { + path: '/', + method: 'GET', + handler: handler +}; + +interface GetThingQuery { + name: string; +} + +const server = new Server(options); +server.route(serverRoute); +server.start(); +console.log('Server started at: ' + server.info.uri);