favicon serving middleware with caching
Node.js middleware for serving a favicon.
A favicon is a visual cue that client software, like browsers, use to identify a site. For an example and more information, please visit the Wikipedia article on favicons.
Why use this module?
favicon.icofrequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.
ETagbased on the contents of the icon, rather than file system properties.
Note This module is exclusively for serving the "default, implicit favicon",
GET /favicon.ico. For additional vendor-specific icons that require
HTML markup, additional middleware is required to serve the relevant files, for
npm install serve-favicon
Create new middleware to serve a favicon from the given
path to a favicon file.
path may also be a
Buffer of the icon to serve.
Serve favicon accepts these properties in the options object.
max-age directive in
ms, defaulting to 1 year. This can
also be a string accepted by the ms
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
var express = require'express';var favicon = require'serve-favicon';var app = express;appusefavicon__dirname + '/public/favicon.ico';// Add your routes here, etc.applisten3000;
var connect = require'connect';var favicon = require'serve-favicon';var app = connect;appusefavicon__dirname + '/public/favicon.ico';// Add your middleware here, etc.applisten3000;
This middleware can be used anywhere, even outside express/connect. It takes
var http = require'http';var favicon = require'serve-favicon';var finalhandler = require'finalhandler';var _favicon = favicon__dirname + '/public/favicon.ico';var server = httpcreateServervar done = finalhandlerreq res;_faviconreq resif err return doneerr;// continue to process the request here, etc.resstatusCode = 404;resend'oops';;;serverlisten3000;