pax_global_header 0000666 0000000 0000000 00000000064 12415261157 0014516 g ustar 00root root 0000000 0000000 52 comment=f1308134d21aeaf5849a3d41c3a04b1779819f3c
serve-static-1.6.4/ 0000775 0000000 0000000 00000000000 12415261157 0014137 5 ustar 00root root 0000000 0000000 serve-static-1.6.4/.gitignore 0000664 0000000 0000000 00000000046 12415261157 0016127 0 ustar 00root root 0000000 0000000 coverage/
node_modules/
npm-debug.log
serve-static-1.6.4/.travis.yml 0000664 0000000 0000000 00000000371 12415261157 0016251 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"
matrix:
allow_failures:
- node_js: "0.11"
fast_finish: true
script: "npm run-script test-travis"
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
serve-static-1.6.4/HISTORY.md 0000664 0000000 0000000 00000007043 12415261157 0015626 0 ustar 00root root 0000000 0000000 1.6.4 / 2014-10-08
==================
* Fix redirect loop when index file serving disabled
1.6.3 / 2014-09-24
==================
* deps: send@0.9.3
- deps: etag@~1.4.0
1.6.2 / 2014-09-15
==================
* deps: send@0.9.2
- deps: depd@0.4.5
- deps: etag@~1.3.1
- deps: range-parser@~1.0.2
1.6.1 / 2014-09-07
==================
* deps: send@0.9.1
- deps: fresh@0.2.4
1.6.0 / 2014-09-07
==================
* deps: send@0.9.0
- Add `lastModified` option
- Use `etag` to generate `ETag` header
- deps: debug@~2.0.0
1.5.4 / 2014-09-04
==================
* deps: send@0.8.5
- Fix a path traversal issue when using `root`
- Fix malicious path detection for empty string path
1.5.3 / 2014-08-17
==================
* deps: send@0.8.3
1.5.2 / 2014-08-14
==================
* deps: send@0.8.2
- Work around `fd` leak in Node.js 0.10 for `fs.ReadStream`
1.5.1 / 2014-08-09
==================
* Fix parsing of weird `req.originalUrl` values
* deps: parseurl@~1.3.0
* deps: utils-merge@1.0.0
1.5.0 / 2014-08-05
==================
* deps: send@0.8.1
- Add `extensions` option
1.4.4 / 2014-08-04
==================
* deps: send@0.7.4
- Fix serving index files without root dir
1.4.3 / 2014-07-29
==================
* deps: send@0.7.3
- Fix incorrect 403 on Windows and Node.js 0.11
1.4.2 / 2014-07-27
==================
* deps: send@0.7.2
- deps: depd@0.4.4
1.4.1 / 2014-07-26
==================
* deps: send@0.7.1
- deps: depd@0.4.3
1.4.0 / 2014-07-21
==================
* deps: parseurl@~1.2.0
- Cache URLs based on original value
- Remove no-longer-needed URL mis-parse work-around
- Simplify the "fast-path" `RegExp`
* deps: send@0.7.0
- Add `dotfiles` option
- deps: debug@1.0.4
- deps: depd@0.4.2
1.3.2 / 2014-07-11
==================
* deps: send@0.6.0
- Cap `maxAge` value to 1 year
- deps: debug@1.0.3
1.3.1 / 2014-07-09
==================
* deps: parseurl@~1.1.3
- faster parsing of href-only URLs
1.3.0 / 2014-06-28
==================
* Add `setHeaders` option
* Include HTML link in redirect response
* deps: send@0.5.0
- Accept string for `maxAge` (converted by `ms`)
1.2.3 / 2014-06-11
==================
* deps: send@0.4.3
- Do not throw un-catchable error on file open race condition
- Use `escape-html` for HTML escaping
- deps: debug@1.0.2
- deps: finished@1.2.2
- deps: fresh@0.2.2
1.2.2 / 2014-06-09
==================
* deps: send@0.4.2
- fix "event emitter leak" warnings
- deps: debug@1.0.1
- deps: finished@1.2.1
1.2.1 / 2014-06-02
==================
* use `escape-html` for escaping
* deps: send@0.4.1
- Send `max-age` in `Cache-Control` in correct format
1.2.0 / 2014-05-29
==================
* deps: send@0.4.0
- Calculate ETag with md5 for reduced collisions
- Fix wrong behavior when index file matches directory
- Ignore stream errors after request ends
- Skip directories in index file search
- deps: debug@0.8.1
1.1.0 / 2014-04-24
==================
* Accept options directly to `send` module
* deps: send@0.3.0
1.0.4 / 2014-04-07
==================
* Resolve relative paths at middleware setup
* Use parseurl to parse the URL from request
1.0.3 / 2014-03-20
==================
* Do not rely on connect-like environments
1.0.2 / 2014-03-06
==================
* deps: send@0.2.0
1.0.1 / 2014-03-05
==================
* Add mime export for back-compat
1.0.0 / 2014-03-05
==================
* Genesis from `connect`
serve-static-1.6.4/LICENSE 0000664 0000000 0000000 00000002240 12415261157 0015142 0 ustar 00root root 0000000 0000000 (The MIT License)
Copyright (c) 2010 Sencha Inc.
Copyright (c) 2011 LearnBoost
Copyright (c) 2011 TJ Holowaychuk
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
serve-static-1.6.4/README.md 0000664 0000000 0000000 00000010352 12415261157 0015417 0 ustar 00root root 0000000 0000000 # serve-static
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Gratipay][gratipay-image]][gratipay-url]
## Install
```sh
$ npm install serve-static
```
## API
```js
var serveStatic = require('serve-static')
```
### serveStatic(root, options)
Create a new middleware function to serve files from within a given root
directory. The file to serve will be determined by combining `req.url`
with the provided root directory. When a file is not found, instead of
sending a 404 response, this module will instead call `next()` to move on
to the next middleware, allowing for stacking and fall-backs.
#### Options
##### dotfiles
Set how "dotfiles" are treated when encountered. A dotfile is a file
or directory that begins with a dot ("."). Note this check is done on
the path itself without checking if the path actually exists on the
disk. If `root` is specified, only the dotfiles above the root are
checked (i.e. the root itself can be within a dotfile when when set
to "deny").
The default value is `'ignore'`.
- `'allow'` No special treatment for dotfiles.
- `'deny'` Send a 403 for any request for a dotfile.
- `'ignore'` Pretend like the dotfile does not exist and call `next()`.
##### etag
Enable or disable etag generation, defaults to true.
##### extensions
Set file extension fallbacks. When set, if a file is not found, the given
extensions will be added to the file name and search for. The first that
exists will be served. Example: `['html', 'htm']`.
The default value is `false`.
##### index
By default this module will send "index.html" files in response to a request
on a directory. To disable this set `false` or to supply a new index pass a
string or an array in preferred order.
##### lastModified
Enable or disable `Last-Modified` header, defaults to true. Uses the file
system's last modified value.
##### maxAge
Provide a max-age in milliseconds for http caching, defaults to 0. This
can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
module.
##### redirect
Redirect to trailing "/" when the pathname is a dir. Defaults to `true`.
##### setHeaders
Function to set custom headers on response.
## Examples
### Serve files with vanilla node.js http server
```js
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
// Serve up public/ftp folder
var serve = serveStatic('public/ftp', {'index': ['index.html', 'index.htm']})
// Create server
var server = http.createServer(function(req, res){
var done = finalhandler(req, res)
serve(req, res, done)
})
// Listen
server.listen(3000)
```
### Serve all files as downloads
```js
var contentDisposition = require('content-disposition')
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
// Serve up public/ftp folder
app.use(serveStatic('public/ftp', {
'index': false,
'setHeaders': setHeaders
}))
// Set header to force download
function setHeaders(res, path) {
res.setHeader('Content-Disposition', contentDisposition(path))
}
// Create server
var server = http.createServer(function(req, res){
var done = finalhandler(req, res)
serve(req, res, done)
})
// Listen
server.listen(3000)
```
### Serving using express
```js
var connect = require('connect')
var serveStatic = require('serve-static')
var app = connect()
app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']}))
app.listen(3000)
```
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/serve-static.svg?style=flat
[npm-url]: https://npmjs.org/package/serve-static
[travis-image]: https://img.shields.io/travis/expressjs/serve-static.svg?style=flat
[travis-url]: https://travis-ci.org/expressjs/serve-static
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-static.svg?style=flat
[coveralls-url]: https://coveralls.io/r/expressjs/serve-static
[downloads-image]: https://img.shields.io/npm/dm/serve-static.svg?style=flat
[downloads-url]: https://npmjs.org/package/serve-static
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
[gratipay-url]: https://gratipay.com/dougwilson/
serve-static-1.6.4/index.js 0000664 0000000 0000000 00000005332 12415261157 0015607 0 ustar 00root root 0000000 0000000 /*!
* serve-static
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var escapeHtml = require('escape-html');
var merge = require('utils-merge');
var parseurl = require('parseurl');
var resolve = require('path').resolve;
var send = require('send');
var url = require('url');
/**
* @param {String} root
* @param {Object} options
* @return {Function}
* @api public
*/
exports = module.exports = function serveStatic(root, options) {
if (!root) {
throw new TypeError('root path required')
}
if (typeof root !== 'string') {
throw new TypeError('root path must be a string')
}
// copy options object
options = merge({}, options)
// resolve root to absolute
root = resolve(root)
// default redirect
var redirect = options.redirect !== false
// headers listener
var setHeaders = options.setHeaders
delete options.setHeaders
if (setHeaders && typeof setHeaders !== 'function') {
throw new TypeError('option setHeaders must be function')
}
// setup options for send
options.maxage = options.maxage || options.maxAge || 0
options.root = root
return function serveStatic(req, res, next) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
return next()
}
var opts = merge({}, options)
var originalUrl = parseurl.original(req)
var path = parseurl(req).pathname
var hasTrailingSlash = originalUrl.pathname[originalUrl.pathname.length - 1] === '/'
if (path === '/' && !hasTrailingSlash) {
// make sure redirect occurs at mount
path = ''
}
// create send stream
var stream = send(req, path, opts)
if (redirect) {
// redirect relative to originalUrl
stream.on('directory', function redirect() {
if (hasTrailingSlash) {
return next()
}
originalUrl.pathname += '/'
var target = url.format(originalUrl)
res.statusCode = 303
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.setHeader('Location', target)
res.end('Redirecting to ' + escapeHtml(target) + '\n')
})
} else {
// forward to next middleware on directory
stream.on('directory', next)
}
// add headers listener
if (setHeaders) {
stream.on('headers', setHeaders)
}
// forward non-404 errors
stream.on('error', function error(err) {
next(err.status === 404 ? null : err)
})
// pipe
stream.pipe(res)
}
}
/**
* Expose mime module.
*
* If you wish to extend the mime table use this
* reference to the "mime" module in the npm registry.
*/
exports.mime = send.mime
serve-static-1.6.4/package.json 0000664 0000000 0000000 00000001657 12415261157 0016436 0 ustar 00root root 0000000 0000000 {
"name": "serve-static",
"description": "Serve static files",
"version": "1.6.4",
"author": "Douglas Christopher Wilson ",
"license": "MIT",
"repository": "expressjs/serve-static",
"dependencies": {
"escape-html": "1.0.1",
"parseurl": "~1.3.0",
"send": "0.9.3",
"utils-merge": "1.0.0"
},
"devDependencies": {
"istanbul": "0.3.2",
"mocha": "~1.21.0",
"should": "~4.0.0",
"supertest": "~0.14.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks --require should test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks --require should test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks --require should test/"
}
}
serve-static-1.6.4/test/ 0000775 0000000 0000000 00000000000 12415261157 0015116 5 ustar 00root root 0000000 0000000 serve-static-1.6.4/test/fixtures/ 0000775 0000000 0000000 00000000000 12415261157 0016767 5 ustar 00root root 0000000 0000000 serve-static-1.6.4/test/fixtures/.hidden 0000664 0000000 0000000 00000000013 12415261157 0020215 0 ustar 00root root 0000000 0000000 I am hidden serve-static-1.6.4/test/fixtures/foo bar 0000664 0000000 0000000 00000000003 12415261157 0020213 0 ustar 00root root 0000000 0000000 baz serve-static-1.6.4/test/fixtures/nums 0000664 0000000 0000000 00000000011 12415261157 0017664 0 ustar 00root root 0000000 0000000 123456789 serve-static-1.6.4/test/fixtures/todo.html 0000664 0000000 0000000 00000000022 12415261157 0020614 0 ustar 00root root 0000000 0000000 groceries