diff --git a/docs/guides/hapi-plugin.rst b/docs/guides/hapi-plugin.rst index f21f0ccf6..5557d1fc1 100644 --- a/docs/guides/hapi-plugin.rst +++ b/docs/guides/hapi-plugin.rst @@ -1,42 +1,33 @@ -Using Hoodie as hapi plugin -=========================== - -Here is an example usage of Hoodie as a hapi plugin: - -.. code:: js - - var Hapi = require('hapi') - var hoodie = require('hoodie').register - var PouchDB = require('pouchdb-core') - .plugin(require('pouchdb-mapreduce')) - .plugin(require('pouchdb-adapter-memory')) - - var server = new Hapi.Server() - server.connection({ - host: 'localhost', - port: 8000 - }) - - server.register({ - register: hoodie, - options: { // pass options here - inMemory: true, - public: 'dist', - PouchDB: PouchDB - } - }, function (error) { - if (error) { - throw error - } - - server.start(function (error) { - if (error) { - throw error - } - - console.log(('Server running at:', server.info.uri)) - }) - }) +const Hapi = require('@hapi/hapi'); +const Hoodie = require('hoodie').register; + +const PouchDB = require('pouchdb-core') + .plugin(require('pouchdb-mapreduce')) + .plugin(require('pouchdb-adapter-memory')); + +async function start() { + const server = Hapi.server({ + host: 'localhost', + port: 8000 + }); + + await server.register({ + plugin: Hoodie, + options: { + inMemory: true, + public: 'dist', + PouchDB + } + }); + + await server.start(); + console.log(`Server running at: ${server.info.uri}`); +} + +start().catch(err => { + console.error(err); + process.exit(1); +}); The available options are