https://github.com/stipsan/serve-dynamic-favicon
middleware that serve dynamically generated favicons
https://github.com/stipsan/serve-dynamic-favicon
Last synced: about 1 month ago
JSON representation
middleware that serve dynamically generated favicons
- Host: GitHub
- URL: https://github.com/stipsan/serve-dynamic-favicon
- Owner: stipsan
- Created: 2015-07-17T10:43:33.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T17:30:59.000Z (over 2 years ago)
- Last Synced: 2026-03-14T18:08:08.002Z (3 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# serve-dynamic-favicon
[](https://www.npmjs.com/package/serve-dynamic-favicon)
[](https://nodei.co/npm/serve-dynamic-favicon/)
# PLEASE NOTE THIS IS IN ALPHA
Node.js middleware for serving a favicon that is generated on the fly.
Using the first letter of the the `` tag overlayed a background color fetched from the `` you'll reduce the cognitive load when switching between browser tabs.
You may specify any url you want for where the metadata will be fetched from, or you can pass the letter and theme-color and save the initial request.
This is very useful for when you're running expressjs or BrowserSync servers.
## Install
```bash
npm install serve-dynamic-favicon --production --no-optional
```
## API
### favicon(url:string || options:object)
Create new middleware to serve a favicon generated from metadata fetched from the given `url` to a fetchable html document.
Pass an object with options to switch the middleware from auto mode to manual mode. Manual mode require you to at least specify `themeColor`. `symbol` is optional, omitting it will render a solid color without any foreground text as logo.
#### Options
##### themeColor
The backdrop color to the generated icon. Any css color value, with or without alpha, is supported.
##### symbol
The text letter, usually the first character found in the `` tag when `url` is defined.
##### symbolColor
Optionally set the color of `symbol`. Defaults to `#ffffff`.
## 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`.
### express
```javascript
var express = require('express');
var favicon = require('serve-dynamic-favicon');
var app = express();
app.use(favicon('https://github.com'));
// Add your routes here, etc.
app.listen(3000);
```
### connect
```javascript
var connect = require('connect');
var favicon = require('serve-dynamic-favicon');
var app = connect();
app.use(favicon('https://github.com'));
// Add your middleware here, etc.
app.listen(3000);
```
### vanilla http server
This middleware can be used anywhere, even outside express/connect. It takes
`req`, `res`, and `callback`.
```javascript
var http = require('http');
var favicon = require('serve-dynamic-favicon');
var finalhandler = require('finalhandler');
var _favicon = favicon();
var server = http.createServer(function onRequest(req, res) {
var done = finalhandler(req, res);
_favicon(req, res, function onNext(err) {
if (err) return done(err);
// continue to process the request here, etc.
res.statusCode = 404;
res.end('oops');
});
});
server.listen(3000);
```
## License
[MIT](LICENSE)