From 20071f50f29559208dedbefc80b4669c35ac2295 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Feb 2017 19:13:50 +0100 Subject: [PATCH] Perfected docs for programmatic API --- readme.md | 53 ++++++++++------------------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/readme.md b/readme.md index 3cb60998..6cb52fc2 100644 --- a/readme.md +++ b/readme.md @@ -38,60 +38,27 @@ If you set the `--auth` flag, the package will look for a username and password ## API -Install it (needs at least Node LTS): +You can also use the package inside your application. Just load it: -```bash -npm install serve +```js +const serve = require('serve') ``` -You can now use it in your code: +And call it with flags (run [this command](#options) for the full list): ```js -const serve = require('serve') - -const options = { +const server = serve({ port: 1337, - cache: 0 -} - -const server = serve(options) + ignore: ['node_modules'] +}) +``` -// ... +Later in the code, you can stop the server using this method: +```js server.stop() - ``` -### Options - -#### `port: number` - -Port to listen on - -#### `cache: number` - -Time in milliseconds for caching files in the browser - -#### `single: boolean` - -Serve single page apps with only one `index.html` - -#### `unzipped: boolean` - -Disable GZIP compression - -#### `ignore: string[]` - -Files and directories to ignore - -#### `auth: boolean` - -Serve behind basic auth - -#### `cors: boolean` - -Setup * CORS headers to allow requests from any origin - ## Contributing 1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device