serve-favicon
Advanced tools
Comparing version 2.0.1 to 2.1.0
31
index.js
@@ -13,5 +13,6 @@ /*! | ||
var crypto = require('crypto'); | ||
var etag = require('etag'); | ||
var fresh = require('fresh'); | ||
var fs = require('fs'); | ||
var ms = require('ms'); | ||
var path = require('path'); | ||
@@ -21,2 +22,8 @@ var resolve = path.resolve; | ||
/** | ||
* Module variables. | ||
*/ | ||
var maxMaxAge = 60 * 60 * 24 * 365 * 1000; // 1 year | ||
/** | ||
* Serves the favicon located by the given `path`. | ||
@@ -35,5 +42,3 @@ * | ||
var icon; // favicon cache | ||
var maxAge = options.maxAge == null | ||
? 86400000 | ||
: Math.min(Math.max(0, options.maxAge), 31556926000); | ||
var maxAge = calcMaxAge(options.maxAge); | ||
var stat; | ||
@@ -76,2 +81,12 @@ | ||
function calcMaxAge(val) { | ||
var num = typeof val === 'string' | ||
? ms(val) | ||
: val; | ||
return num != null | ||
? Math.min(Math.max(0, num), maxMaxAge) | ||
: maxMaxAge | ||
} | ||
function createIcon(buf, maxAge) { | ||
@@ -98,10 +113,2 @@ return { | ||
function etag(buf){ | ||
var hash = crypto | ||
.createHash('md5') | ||
.update(buf) | ||
.digest('base64'); | ||
return '"' + hash + '"'; | ||
} | ||
function send(req, res, icon){ | ||
@@ -108,0 +115,0 @@ var _fresh = fresh(req.headers, icon.headers); |
{ | ||
"name": "serve-favicon", | ||
"description": "favicon serving middleware with caching", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"express", | ||
"favicon", | ||
@@ -13,7 +14,9 @@ "middleware" | ||
"dependencies": { | ||
"etag": "~1.2.0", | ||
"fresh": "0.2.2" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "0.2.10", | ||
"mocha": "~1.20.1", | ||
"istanbul": "0.3.0", | ||
"mocha": "~1.21.4", | ||
"ms": "0.6.2", | ||
"proxyquire": "~1.0.1", | ||
@@ -23,2 +26,7 @@ "should": "~4.0.1", | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"HISTORY.md", | ||
"index.js" | ||
], | ||
"engines": { | ||
@@ -28,6 +36,6 @@ "node": ">= 0.8.0" | ||
"scripts": { | ||
"test": "mocha --reporter dot test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/" | ||
"test": "mocha --reporter spec --bail --check-leaks test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" | ||
} | ||
} |
# serve-favicon | ||
[![NPM version](https://badge.fury.io/js/serve-favicon.svg)](http://badge.fury.io/js/serve-favicon) | ||
[![Build Status](https://travis-ci.org/expressjs/serve-favicon.svg?branch=master)](https://travis-ci.org/expressjs/serve-favicon) | ||
[![Coverage Status](https://img.shields.io/coveralls/expressjs/serve-favicon.svg?branch=master)](https://coveralls.io/r/expressjs/serve-favicon) | ||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![Test Coverage][coveralls-image]][coveralls-url] | ||
[![Gittip][gittip-image]][gittip-url] | ||
@@ -11,3 +13,5 @@ Node.js middleware for serving a favicon. | ||
npm install serve-favicon | ||
```bash | ||
npm install serve-favicon | ||
``` | ||
@@ -21,11 +25,19 @@ ## API | ||
#### options | ||
#### Options | ||
- `maxAge` - cache-control max-age directive in `ms`, defaulting to 1 day. | ||
Serve favicon accepts these properties in the options object. | ||
##### maxAge | ||
The `cache-control` `max-age` directive in `ms`, defaulting to 1 day. This can | ||
also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme) | ||
module. | ||
## Examples | ||
Typically this middleware will come very early in your stack (maybe even first) to avoid processing any other middleware if we already know the request is for `/favicon.ico`. | ||
Typically this middleware will come very early in your stack (maybe even first) | ||
to avoid processing any other middleware if we already know the request is for | ||
`/favicon.ico`. | ||
### express 3.x/4.x | ||
### express | ||
@@ -60,3 +72,4 @@ ```javascript | ||
This middleware can be used anywhere, even outside express/connect. It takes `req`, `res`, and `callback`. | ||
This middleware can be used anywhere, even outside express/connect. It takes | ||
`req`, `res`, and `callback`. | ||
@@ -66,2 +79,3 @@ ```javascript | ||
var favicon = require('serve-favicon'); | ||
var finalhandler = require('finalhandler'); | ||
@@ -71,8 +85,6 @@ var _favicon = favicon(__dirname + '/public/favicon.ico'); | ||
var server = http.createServer(function onRequest(req, res) { | ||
var done = finalhandler(req, res); | ||
_favicon(req, res, function onNext(err) { | ||
if (err) { | ||
res.statusCode = 500; | ||
res.end(); | ||
return; | ||
} | ||
if (err) return done(err); | ||
@@ -92,1 +104,12 @@ // continue to process the request here, etc. | ||
[MIT](LICENSE) | ||
[npm-image]: https://img.shields.io/npm/v/serve-favicon.svg?style=flat | ||
[npm-url]: https://npmjs.org/package/serve-favicon | ||
[travis-image]: https://img.shields.io/travis/expressjs/serve-favicon.svg?style=flat | ||
[travis-url]: https://travis-ci.org/expressjs/serve-favicon | ||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-favicon.svg?style=flat | ||
[coveralls-url]: https://coveralls.io/r/expressjs/serve-favicon?branch=master | ||
[downloads-image]: http://img.shields.io/npm/dm/serve-favicon.svg?style=flat | ||
[downloads-url]: https://npmjs.org/package/serve-favicon | ||
[gittip-image]: https://img.shields.io/gittip/dougwilson.svg?style=flat | ||
[gittip-url]: https://www.gittip.com/dougwilson/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8272
96
110
2
6
5
+ Addedetag@~1.2.0
+ Addedbuffer-crc32@0.2.3(transitive)
+ Addedetag@1.2.1(transitive)