本文整理汇总了TypeScript中hapi.Server.event方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.event方法的具体用法?TypeScript Server.event怎么用?TypeScript Server.event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.Server
的用法示例。
在下文中一共展示了Server.event方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Server
// from https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncecriteria-listener
import { Request, ResponseToolkit, Server, ServerRoute } from "hapi";
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler: (request: Request, h: ResponseToolkit) => {
return 'oks: ' + request.path;
}
};
const server = new Server({
port: 8000,
});
server.route(serverRoute);
server.event('test1');
server.event('test2');
server.events.once('test1', (update: any) => { console.log(update); });
server.events.once('test2', (...args: any[]) => { 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:
// From https://hapijs.com/api/16.1.1#serveremitcriteria-data-callback
import * as Hapi from 'hapi';
const server = new Hapi.Server();
server.connection({ port: 80 });
server.event('test');
server.on('test', (update: Update) => console.log(update));
type Update = string;
var toSend: Update = 'hello';
server.emit('test', toSend);