2.3.0 • Published 4 years ago

hecks v2.3.0

Weekly downloads
213
License
MIT
Repository
github
Last release
4 years ago

hecks

Mount your express app onto your hapi server, aw heck!

Build Status Coverage Status

Lead Maintainer - Devin Ivy

Usage

See also the API Reference

Hecks allows you to seamlessly incorporate express applications into a hapi v17+ server. This is particularly useful for testing an express server using server.inject(), for unifying deployment of existing express and hapi applications, and as an initial stepping stone in migrating an express application to hapi.

const Express = require('express');
const BodyParser = require('body-parser');
const Hapi = require('@hapi/hapi');
const Hoek = require('@hapi/hoek');
const Hecks = require('hecks');

(async () => {

    const app = Express();

    app.post('/user', BodyParser.json(), (req, res) => {

        const user = Hoek.shallow(req.body);
        user.saved = true;

        res.json(user);
    });

    const server = Hapi.server();

    await server.register([
        Hecks.toPlugin(app, 'my-express-app')
    ]);

    const { result } = await server.inject({
        method: 'post',
        url: '/user',
        payload: { name: 'Bill', faveFood: 'cactus' }
    });

    console.log(result); // {"name":"Bill","faveFood":"cactus","saved":true}
})();
2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago