Added some test files.

This commit is contained in:
rafaelsouzaf
2017-12-06 00:11:51 -03:00
parent 5334e6bf7e
commit 88a3292c9d
6 changed files with 122 additions and 0 deletions
@@ -0,0 +1,41 @@
// from https://hapijs.com/tutorials/getting-started#adding-routes
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const server = new Server(options);
const serverRoute: ServerRoute = {
path: '/user',
method: 'GET',
handler: function (request: Request, h: ResponseToolkit) {
console.log(request);
return 'ok: ' + request.path;
}
}
const serverRoutes: ServerRoute[] = [
{
path: '/test1',
method: 'GET',
handler: function (request: Request, h: ResponseToolkit) {
console.log(request);
return 'ok: ' + request.path;
}
},
{
path: '/test2',
method: 'GET',
handler: function (request: Request, h: ResponseToolkit) {
console.log(request);
return 'ok: ' + request.path;
}
},
];
server.route(serverRoute);
server.route(serverRoutes);
server.start();
console.log(`Server running at: ${server.info!.uri}`);
+7
View File
@@ -10,3 +10,10 @@
/** Getting Started */
export * from './getting-started/01-creating-a-server';
export * from './getting-started/02-adding-routes';
export * from './path/catch-all';
export * from './server/app';
export * from './server/info';
export * from './server/table';
+15
View File
@@ -0,0 +1,15 @@
// From https://github.com/hapijs/hapi/blob/master/API.md#catch-all-route
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const server = new Server(options);
const handler = function (request: Request, h: ResponseToolkit) {
return h.response('The page was not found').code(404);
};
server.route({ method: '*', path: '/{p*}', handler });
server.start();
console.log(`Server running at: ${server.info!.uri}`);
+22
View File
@@ -0,0 +1,22 @@
// From https://github.com/hapijs/hapi/blob/master/API.md#-serverapp
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const server = new Server(options);
server.app.key = 'value2';
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler: function (request: Request, h: ResponseToolkit) {
return 'key: ' + request.server.app.key;
}
}
server.route(serverRoute);
server.start();
console.log(`Server running at: ${server.info!.uri}`);
+15
View File
@@ -0,0 +1,15 @@
// From https://github.com/hapijs/hapi/blob/master/API.md#-serverinfo
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
import assert = require('assert');
let options: ServerOptions = {
port: 8000,
};
const server = new Server(options);
// check the correct port
if(server.info) assert(server.info.port === 8000);
assert(server.info !== null);
server.start();
console.log(`Server running at: ${server.info!.uri}`);
+22
View File
@@ -0,0 +1,22 @@
// From https://github.com/hapijs/hapi/blob/master/API.md#-servertablehost
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const server = new Server(options);
server.app.key = 'value2';
server.route({
path: '/',
method: 'GET',
handler: function (request: Request, h: ResponseToolkit) {
return h.response("Hello World");
}
});
server.start();
const table = server.table();
console.log(table);
console.log(`Server running at: ${server.info!.uri}`);