Skip to content

Commit

Permalink
Write readme usage/example, add bare API.md
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Mar 9, 2017
1 parent 48fe320 commit 74ed17e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
10 changes: 10 additions & 0 deletions API.md
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
40 changes: 38 additions & 2 deletions README.md
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}
});
});
```

0 comments on commit 74ed17e

Please sign in to comment.