Skip to content

Commit

Permalink
Added example of using the middleware (#385)
Browse files Browse the repository at this point in the history
* Added example of using the middleware

* Removed newline
  • Loading branch information
leo committed May 29, 2018
1 parent a567a0a commit 2c8a701
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,24 @@ To customize `serve`'s behavior, create a `serve.json` file and insert any of [t

## API

The core of `serve` is [serve-handler](https://github.com/zeit/serve-handler), which can be used as middleware in existing HTTP servers.
The core of `serve` is [serve-handler](https://github.com/zeit/serve-handler), which can be used as middleware in existing HTTP servers:

```js
const handler = require('serve-handler');
const http = require('http');

const server = http.createServer((request, response) => {
// You pass two more arguments for config and middleware
// More details here: https://github.com/zeit/serve-handler#options
return handler(request, response);
})

server.listen(3000, () => {
console.log('Listening on http://localhost:3000');
});
```

**NOTE:** You can also replace `http.createServer` with [micro](https://github.com/zeit/micro), if you want.

## Contributing

Expand Down

0 comments on commit 2c8a701

Please sign in to comment.