Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Latest commit

 

History

History
62 lines (48 loc) · 1.39 KB

File metadata and controls

62 lines (48 loc) · 1.39 KB

Example of a Hapi app using the Funksie plugin

This example depends on scooter and funksie to function.

'use strict';

const Hapi = require('@hapi/hapi');
const Scooter = require('@hapi/scooter');
const Funksie = require('funksie');

const init = async () => {

    const server = Hapi.server({
        port: 3000,
        host: 'localhost'
    });

    await server.register([Scooter, {
        plugin: Funksie,
        options: {} // specify options here
    }]);

    // This endpoint gets the default configuration for funksie
    server.route({
        method: 'GET',
        path: '/',
        handler: (request, h) => {

            return 'Hello World!';
        }
     });

    // This endpoint has a route specific configuration where autoplay: 'www.example.com'
    server.route({
    method: 'GET',
    path: '/something',
    config: {
        handler: (request, h) => {

            return h.response('these settings are changed').header('X-Custom', 'some-value');
        },
        plugins: {
            funksie: {
                autoplaySrc: 'www.example.com'
                }
            }
        }
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {

    console.log(err);
    process.exit(1);
});

init();