fix: allow for synchronous Hapi plugin register fn

This commit is contained in:
Stephan Schneider
2018-03-07 15:23:58 +01:00
parent cbe61c4db1
commit 091f2f4271
2 changed files with 14 additions and 1 deletions

View File

@@ -120,7 +120,7 @@ export interface PluginBase<T> {
* * server - the server object with a plugin-specific server.realm.
* * options - any options passed to the plugin during registration via server.register().
*/
register: (server: Server, options: T) => Promise<void>;
register: (server: Server, options: T) => void | Promise<void>;
/** (optional) if true, allows the plugin to be registered multiple times with the same server. Defaults to false. */
multiple?: boolean;

View File

@@ -13,6 +13,10 @@ interface Plugin3 {
three: 3;
}
interface Plugin4 {
four: 4;
}
declare module 'hapi' {
interface PluginProperties {
example: {
@@ -42,6 +46,11 @@ const plugin3: Plugin<Plugin3> = {
register: async (server: Server, options: Plugin3) => {}
};
const plugin4: Plugin<Plugin4> = {
name: 'plugin4',
register: (server: Server, options: Plugin4) => {}
};
const server = new Server({
port: 8000,
});
@@ -90,5 +99,9 @@ server.register([
{
plugin: plugin1,
options: {one: 1}
},
{
plugin: plugin4,
options: {four: 4}
}
]);