mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Added some test files.
This commit is contained in:
@@ -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}`);
|
||||
Vendored
+7
@@ -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';
|
||||
|
||||
|
||||
|
||||
@@ -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}`);
|
||||
@@ -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}`);
|
||||
@@ -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}`);
|
||||
@@ -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}`);
|
||||
Reference in New Issue
Block a user