https://github.com/hapipal/hecks
Mount your express app onto your hapi server, aw heck!
https://github.com/hapipal/hecks
Last synced: 12 months ago
JSON representation
Mount your express app onto your hapi server, aw heck!
- Host: GitHub
- URL: https://github.com/hapipal/hecks
- Owner: hapipal
- License: mit
- Created: 2017-03-06T05:20:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T03:52:24.000Z (about 5 years ago)
- Last Synced: 2025-04-27T16:02:42.254Z (about 1 year ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 30
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hecks
Mount your express app onto your hapi server, aw heck!
[](https://travis-ci.com/hapipal/hecks) [](https://coveralls.io/github/hapipal/hecks?branch=master)
Lead Maintainer - [Devin Ivy](https://github.com/devinivy)
## Installation
```sh
npm install @hapipal/hecks
```
## Usage
> See also the [API Reference](API.md)
>
> 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()`](https://github.com/hapijs/hapi/blob/master/API.md#server.inject()), for unifying deployment of existing express and hapi applications, and as an initial stepping stone in migrating an express application to hapi.
```js
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}
})();
```