From 2c8a7013099390d9b9772fe80d8d02dd23a6c37b Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Tue, 29 May 2018 13:22:36 +0200 Subject: [PATCH] Added example of using the middleware (#385) * Added example of using the middleware * Removed newline --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 744b9e29..3a3b58b1 100644 --- a/README.md +++ b/README.md @@ -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