本文整理汇总了TypeScript中@hapi/hapi.Server.event方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.event方法的具体用法?TypeScript Server.event怎么用?TypeScript Server.event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@hapi/hapi.Server
的用法示例。
在下文中一共展示了Server.event方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handler
import { Request, ResponseToolkit, Server, ServerRoute } from "@hapi/hapi";
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler(request, h) {
return 'oks: ' + request.path;
}
};
declare module '@hapi/hapi' {
interface ServerEvents {
once(event: 'test1', listener: (update: string) => void): this;
once(event: 'test2', listener: (...updates: string[]) => void): this;
}
}
const server = new Server({
port: 8000,
});
server.route(serverRoute);
server.event('test1');
server.event('test2');
server.events.once('test1', update => { console.log(update); });
server.events.once('test2', (...args) => { console.log(args); });
server.events.emit('test1', 'hello-1');
server.events.emit('test2', 'hello-2'); // Ignored
server.start();
console.log('Server started at: ' + server.info.uri);
示例2: require
// https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents
import { Server, ServerEvents } from "@hapi/hapi";
import Podium = require('@hapi/podium');
import '@hapi/hapi/definitions/server/server';
declare module '@hapi/hapi' {
interface ServerEvents {
on(event: 'test', listener: (update: string) => void): this;
}
}
const server = new Server({
port: 8000,
});
server.events.on('route', route => {
console.log(route.path, route.vhost, route.realm, route.method, route.settings, route.fingerprint);
});
server.event('test');
server.events.on('test', (update: any) => console.log(update));
server.events.emit('test', 'hello');
server.start();