Skip to content
forked from hapipal/hecks

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

License

Notifications You must be signed in to change notification settings

postalsys/hecks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

| This is a fork of hapipal/hecks. It changes the peer dependency version for Hapi.

hecks

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

Build Status Coverage Status

Lead Maintainer - Devin Ivy

Installation

npm install @hapipal/hecks

Usage

See also the API Reference

Hecks is intended for use with hapi v19+ and nodejs v12+ (see v2 for lower support).

Hecks allows you to seamlessly incorporate express applications into a hapi 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 Hecks = require('@hapipal/hecks');

(async () => {

    const app = Express();

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

        const user = { ...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}
})();

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%