Skip to content

Commit c5e1bbd

Browse files
committed
docs: expand documentation
1 parent 793a615 commit c5e1bbd

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

Readme.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
[![Build Status](https://travis-ci.org/expressjs/serve-static.svg?branch=master)](https://travis-ci.org/expressjs/serve-static)
55
[![Coverage Status](https://img.shields.io/coveralls/expressjs/serve-static.svg?branch=master)](https://coveralls.io/r/expressjs/serve-static)
66

7-
Previously `connect.static()`.
8-
97
## Install
108

119
```sh
@@ -22,15 +20,50 @@ var serveStatic = require('serve-static')
2220

2321
Create a new middleware function to serve files from within a given root
2422
directory. The file to serve will be determined by combining `req.url`
25-
with the provided root directory.
23+
with the provided root directory. When a file is not found, instead of
24+
sending a 404 response, this module will instead call `next()` to move on
25+
to the next middleware, allowing for stacking and fall-backs.
26+
27+
#### Options
28+
29+
##### dotfiles
30+
31+
Set how "dotfiles" are treated when encountered. A dotfile is a file
32+
or directory that begins with a dot ("."). Note this check is done on
33+
the path itself without checking if the path actually exists on the
34+
disk. If `root` is specified, only the dotfiles above the root are
35+
checked (i.e. the root itself can be within a dotfile when when set
36+
to "deny").
37+
38+
The default value is `'ignore'`.
39+
40+
- `'allow'` No special treatment for dotfiles.
41+
- `'deny'` Send a 403 for any request for a dotfile.
42+
- `'ignore'` Pretend like the dotfile does not exist and call `next()`.
43+
44+
##### etag
45+
46+
Enable or disable etag generation, defaults to true.
47+
48+
##### index
49+
50+
By default this module will send "index.html" files in response to a request
51+
on a directory. To disable this set `false` or to supply a new index pass a
52+
string or an array in preferred order.
53+
54+
##### maxAge
55+
56+
Provide a max-age in milliseconds for http caching, defaults to 0. This
57+
can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
58+
module.
59+
60+
##### redirect
61+
62+
Redirect to trailing "/" when the pathname is a dir. Defaults to `true`.
2663

27-
Options:
64+
##### setHeaders
2865

29-
- `hidden` Allow transfer of hidden files. defaults to `false`
30-
- `index` Default file name, defaults to `'index.html'`
31-
- `maxAge` Browser cache maxAge in milliseconds. This can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme) module. defaults to `0`
32-
- `redirect` Redirect to trailing "/" when the pathname is a dir. defaults to `true`
33-
- `setHeaders` Function to set custom headers on response.
66+
Function to set custom headers on response.
3467

3568
## Examples
3669

0 commit comments

Comments
 (0)