mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
Add more tests files.
This commit is contained in:
Vendored
+2
@@ -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';
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user