本文整理汇总了TypeScript中hapi.Server.subscription方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.subscription方法的具体用法?TypeScript Server.subscription怎么用?TypeScript Server.subscription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.Server
的用法示例。
在下文中一共展示了Server.subscription方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
server.register(Nes).then(() => {
server.subscription('/item/{id}');
return server.start().then(() => {
server.publish('/item/5', {id: 5, status: 'complete'});
server.publish('/item/6', {id: 6, status: 'initial'});
});
})
示例2: async
server.register([Basic, Nes]).then(() => {
// Set up HTTP Basic authentication
interface User {
username: string;
password: string;
name: string;
id: string;
}
const users: {[index: string]: User} = {
john: {
username: 'john',
password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // 'secret'
name: 'John Doe',
id: '2133d32a'
}
};
const validate: Basic.Validate = async (request, username, password, h) => {
const user = users[username];
if (!user) {
return { credentials: null, isValid: false };
}
let isValid = await Bcrypt.compare(password, user.password)
return { isValid, credentials: { id: user.id, name: user.name, username: user.username } };
};
server.auth.strategy('simple', 'basic', { validate });
server.auth.default('simple')
// Set up subscription
server.subscription('/items', {
filter: (path, message, options) => {
return message.updater !== options.credentials.username;
}
});
server.start().then(() => {
server.publish('/items', { id: 5, status: 'complete', updater: 'john' });
server.publish('/items', { id: 6, status: 'initial', updater: 'steve' });
});
});