本文整理匯總了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);