Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / serve-index / README.md
1 # serve-index\r
2 \r
3 [![NPM Version][npm-image]][npm-url]\r
4 [![NPM Downloads][downloads-image]][downloads-url]\r
5 [![Linux Build][travis-image]][travis-url]\r
6 [![Windows Build][appveyor-image]][appveyor-url]\r
7 [![Test Coverage][coveralls-image]][coveralls-url]\r
8 [![Gratipay][gratipay-image]][gratipay-url]\r
9 \r
10   Serves pages that contain directory listings for a given path.\r
11 \r
12 ## Install\r
13 \r
14 ```sh\r
15 $ npm install serve-index\r
16 ```\r
17 \r
18 ## API\r
19 \r
20 ```js\r
21 var serveIndex = require('serve-index')\r
22 ```\r
23 \r
24 ### serveIndex(path, options)\r
25 \r
26 Returns middlware that serves an index of the directory in the given `path`.\r
27 \r
28 The `path` is based off the `req.url` value, so a `req.url` of `'/some/dir`\r
29 with a `path` of `'public'` will look at `'public/some/dir'`. If you are using\r
30 something like `express`, you can change the URL "base" with `app.use` (see\r
31 the express example).\r
32 \r
33 #### Options\r
34 \r
35 Serve index accepts these properties in the options object.\r
36 \r
37 ##### filter\r
38 \r
39 Apply this filter function to files. Defaults to `false`. The `filter` function\r
40 is called for each file, with the signature `filter(filename, index, files, dir)`\r
41 where `filename` is the name of the file, `index` is the array index, `files` is\r
42 the array of files and `dir` is the absolute path the file is located (and thus,\r
43 the directory the listing is for).\r
44 \r
45 ##### hidden\r
46 \r
47 Display hidden (dot) files. Defaults to `false`.\r
48 \r
49 ##### icons\r
50 \r
51 Display icons. Defaults to `false`.\r
52 \r
53 ##### stylesheet\r
54 \r
55 Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.\r
56 \r
57 ##### template\r
58 \r
59 Optional path to an HTML template or a function that will render a HTML\r
60 string. Defaults to a built-in template.\r
61 \r
62 When given a string, the string is used as a file path to load and then the\r
63 following tokens are replaced in templates:\r
64 \r
65   * `{directory}` with the name of the directory.\r
66   * `{files}` with the HTML of an unordered list of file links.\r
67   * `{linked-path}` with the HTML of a link to the directory.\r
68   * `{style}` with the specified stylesheet and embedded images.\r
69 \r
70 When given as a function, the function is called as `template(locals, callback)`\r
71 and it needs to invoke `callback(error, htmlString)`. The following are the\r
72 provided locals:\r
73 \r
74   * `directory` is the directory being displayed (where `/` is the root).\r
75   * `displayIcons` is a Boolean for if icons should be rendered or not.\r
76   * `fileList` is a sorted array of files in the directory. The array contains\r
77     objects with the following properties:\r
78     - `name` is the relative name for the file.\r
79     - `stat` is a `fs.Stats` object for the file.\r
80   * `path` is the full filesystem path to `directory`.\r
81   * `style` is the default stylesheet or the contents of the `stylesheet` option.\r
82   * `viewName` is the view name provided by the `view` option.\r
83 \r
84 ##### view\r
85 \r
86 Display mode. `tiles` and `details` are available. Defaults to `tiles`.\r
87 \r
88 ## Examples\r
89 \r
90 ### Serve directory indexes with vanilla node.js http server\r
91 \r
92 ```js\r
93 var finalhandler = require('finalhandler')\r
94 var http = require('http')\r
95 var serveIndex = require('serve-index')\r
96 var serveStatic = require('serve-static')\r
97 \r
98 // Serve directory indexes for public/ftp folder (with icons)\r
99 var index = serveIndex('public/ftp', {'icons': true})\r
100 \r
101 // Serve up public/ftp folder files\r
102 var serve = serveStatic('public/ftp')\r
103 \r
104 // Create server\r
105 var server = http.createServer(function onRequest(req, res){\r
106   var done = finalhandler(req, res)\r
107   serve(req, res, function onNext(err) {\r
108     if (err) return done(err)\r
109     index(req, res, done)\r
110   })\r
111 })\r
112 \r
113 // Listen\r
114 server.listen(3000)\r
115 ```\r
116 \r
117 ### Serve directory indexes with express\r
118 \r
119 ```js\r
120 var express    = require('express')\r
121 var serveIndex = require('serve-index')\r
122 \r
123 var app = express()\r
124 \r
125 // Serve URLs like /ftp/thing as public/ftp/thing\r
126 app.use('/ftp', serveIndex('public/ftp', {'icons': true}))\r
127 app.listen()\r
128 ```\r
129 \r
130 ## License\r
131 \r
132 [MIT](LICENSE). The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons\r
133 are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).\r
134 \r
135 [npm-image]: https://img.shields.io/npm/v/serve-index.svg\r
136 [npm-url]: https://npmjs.org/package/serve-index\r
137 [travis-image]: https://img.shields.io/travis/expressjs/serve-index/master.svg?label=linux\r
138 [travis-url]: https://travis-ci.org/expressjs/serve-index\r
139 [appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-index/master.svg?label=windows\r
140 [appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-index\r
141 [coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index/master.svg\r
142 [coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master\r
143 [downloads-image]: https://img.shields.io/npm/dm/serve-index.svg\r
144 [downloads-url]: https://npmjs.org/package/serve-index\r
145 [gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg\r
146 [gratipay-url]: https://www.gratipay.com/dougwilson/\r