An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# serve-dynamic-favicon

[![NPM](https://nodei.co/npm/serve-dynamic-favicon.png?downloads=true)](https://www.npmjs.com/package/serve-dynamic-favicon)
[![NPM](https://nodei.co/npm-dl/serve-dynamic-favicon.png?months=3&height=2)](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)