-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write readme usage/example, add bare API.md
- Loading branch information
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# API | ||
## `Hecks` | ||
### The hapi plugin | ||
You should register Hecks in any plugin that would like to take advantage of its features; it does not take any options. Hecks specifies the `once` [plugin attribute](http://hapijs.com/api#plugins), which means hapi will ensure it is not registered multiple times to the same connection. | ||
|
||
#### `express` handler type | ||
TODO | ||
|
||
### `Hecks.toPlugin(app, nameOrAttributes)` | ||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
# hecks | ||
|
||
Mount your express app onto your hapi server, aw heck! | ||
|
||
[![Build Status](https://travis-ci.org/devinivy/hecks.svg?branch=master)](https://travis-ci.org/devinivy/hecks) [![Coverage Status](https://coveralls.io/repos/devinivy/hecks/badge.svg?branch=master&service=github)](https://coveralls.io/github/devinivy/hecks?branch=master) | ||
|
||
## Usage | ||
> See also the [API Reference](API.md) | ||
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#serverinjectoptions-callback), for unifying deployment of existing express and hapi applications, and as an initial stepping stone in migrating an express application to hapi. | ||
|
||
```js | ||
// :o) | ||
const Express = require('express'); | ||
const BodyParser = require('body-parser'); | ||
const Hapi = require('hapi'); | ||
const Hoek = require('hoek'); | ||
const Hecks = require('hecks'); | ||
|
||
const app = Express(); | ||
|
||
app.post('/user', BodyParser.json(), (req, res) => { | ||
|
||
const user = Hoek.shallow(req.body); | ||
user.saved = true; | ||
|
||
res.json(user); | ||
}); | ||
|
||
const server = new Hapi.Server(); | ||
server.connection(); | ||
|
||
server.register([ | ||
Hecks.toPlugin(app, 'my-express-app') | ||
], (err) => { | ||
|
||
Hoek.assert(!err, err); | ||
|
||
server.inject({ | ||
method: 'post', | ||
url: '/user', | ||
payload: { name: 'Bill', faveFood: 'cactus' } | ||
}, (res) => { | ||
|
||
console.log(res.result); // {"name":"Bill","faveFood":"cactus","saved":true} | ||
}); | ||
}); | ||
``` |