Fastify Plugin to serve the favicon.
With this plugin, Fastify will have a route configured for favicon (usually /favicon.ico
) requests.
const fastify = require('fastify')()
// example without specifying options, searching favicon.ico from project root,
// otherwise returning a default favicon
fastify.register(require('fastify-favicon'))
// or
// example with custom path (usually relative to project root, but could be absolute),
// and custom name; all options are optional
fastify.register(require('fastify-favicon'), { path: './test', name: 'icon.ico', maxAge: 3600 })
fastify.listen({ port: 3000, host: 'localhost' })
// curl http://127.0.0.1:3000/favicon.ico => returning the image, and no error thrown
Fastify ^4.12.0 , Node.js 14.15.0 or later. Note that plugin releases 3.x are for Fastify 3.x, 4.x are for Fastify 4.x, etc.
Source code is all inside main repo: fastify-favicon.
Documentation generated from source code (library API): here.
The plugin exposes a GET handler on the URI /${name}
;
Fastify default favicon is used by default, but a custom one can be used.
Plugin options:
- path (default
__dirname
) for the folder containing the icon - name (default 'favicon.ico') for favicon file name
- maxAge (default 86400) for cache duration in seconds for the image
- Fork it ( https://github.com/smartiniOnGitHub/fastify-favicon/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Licensed under Apache-2.0.