mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Add server route validation test file.
This commit is contained in:
committed by
Justin Simms
parent
ab78281950
commit
b7757327fd
30
types/hapi/test/route/validation.ts
Normal file
30
types/hapi/test/route/validation.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// from https://hapijs.com/tutorials/validation?lang=en_US
|
||||
import { ServerRouteConfig, Request, ResponseToolkit, Server, ServerOptions, ServerRoute } from "hapi";
|
||||
import * as Joi from "joi";
|
||||
|
||||
const options: ServerOptions = {
|
||||
port: 8000,
|
||||
};
|
||||
|
||||
const configObject: ServerRouteConfig = {
|
||||
validate: {
|
||||
params: {
|
||||
name: Joi.string().min(3).max(10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const serverRoute: ServerRoute = {
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
handler: (request: Request, h: ResponseToolkit) => {
|
||||
return 'ok: ' + request.path;
|
||||
},
|
||||
config: configObject
|
||||
};
|
||||
|
||||
const server = new Server(options);
|
||||
server.route(serverRoute);
|
||||
|
||||
server.start();
|
||||
console.log('Server started at: ' + server.info.uri);
|
||||
@@ -39,6 +39,7 @@
|
||||
"test/route/handler.ts",
|
||||
"test/route/route-options.ts",
|
||||
"test/route/route-options-pre.ts",
|
||||
"test/route/validation.ts",
|
||||
"test/server/server-app.ts",
|
||||
"test/server/server-auth-api.ts",
|
||||
"test/server/server-auth-default.ts",
|
||||
|
||||
Reference in New Issue
Block a user