mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 10:35:22 +08:00
fix(hapi): make all ext options properties optional (#25214)
This commit is contained in:
committed by
Wesley Wigham
parent
02ed6f6b49
commit
2d3747f998
6
types/hapi/index.d.ts
vendored
6
types/hapi/index.d.ts
vendored
@@ -2472,15 +2472,15 @@ export interface ServerExtOptions {
|
||||
/**
|
||||
* a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
|
||||
*/
|
||||
before: string | string[];
|
||||
before?: string | string[];
|
||||
/**
|
||||
* a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
|
||||
*/
|
||||
after: string | string[];
|
||||
after?: string | string[];
|
||||
/**
|
||||
* a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
|
||||
*/
|
||||
bind: object;
|
||||
bind?: object;
|
||||
/**
|
||||
* if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or when
|
||||
* adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents
|
||||
// https://github.com/hapijs/hapi/blob/master/API.md#-requestevents
|
||||
import { Lifecycle, Request, ResponseToolkit, RouteOptions, Server, ServerOptions, ServerRoute } from "hapi";
|
||||
import { Lifecycle, Request, Server, ServerOptions, ServerRoute } from "hapi";
|
||||
import * as Crypto from 'crypto';
|
||||
|
||||
const options: ServerOptions = {
|
||||
@@ -10,7 +10,7 @@ const options: ServerOptions = {
|
||||
const serverRoute: ServerRoute = {
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
handler(request, h) {
|
||||
handler(request) {
|
||||
return 'ok: ' + request.path;
|
||||
}
|
||||
};
|
||||
@@ -42,7 +42,7 @@ const onRequest: Lifecycle.Method = (request, h) => {
|
||||
*/
|
||||
const hash = Crypto.createHash('sha1');
|
||||
|
||||
request.events.on("peek", (chunk, encoding) => {
|
||||
request.events.on("peek", (chunk) => {
|
||||
hash.update(chunk);
|
||||
});
|
||||
|
||||
@@ -59,7 +59,9 @@ const onRequest: Lifecycle.Method = (request, h) => {
|
||||
|
||||
const server = new Server(options);
|
||||
server.route(serverRoute);
|
||||
server.ext('onRequest', onRequest);
|
||||
server.ext('onRequest', onRequest, {
|
||||
before: 'test',
|
||||
});
|
||||
|
||||
server.start();
|
||||
console.log('Server started at: ' + server.info.uri);
|
||||
|
||||
Reference in New Issue
Block a user