Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # serve-favicon
  2. [![NPM Version][npm-image]][npm-url]
  3. [![NPM Downloads][downloads-image]][downloads-url]
  4. [![Linux Build][travis-image]][travis-url]
  5. [![Windows Build][appveyor-image]][appveyor-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. Node.js middleware for serving a favicon.
  8. A favicon is a visual cue that client software, like browsers, use to identify
  9. a site. For an example and more information, please visit
  10. [the Wikipedia article on favicons](https://en.wikipedia.org/wiki/Favicon).
  11. Why use this module?
  12. - User agents request `favicon.ico` frequently and indiscriminately, so you
  13. may wish to exclude these requests from your logs by using this middleware
  14. before your logger middleware.
  15. - This module caches the icon in memory to improve performance by skipping
  16. disk access.
  17. - This module provides an `ETag` based on the contents of the icon, rather
  18. than file system properties.
  19. - This module will serve with the most compatible `Content-Type`.
  20. **Note** This module is exclusively for serving the "default, implicit favicon",
  21. which is `GET /favicon.ico`. For additional vendor-specific icons that require
  22. HTML markup, additional middleware is required to serve the relevant files, for
  23. example [serve-static](https://npmjs.org/package/serve-static).
  24. ## Install
  25. This is a [Node.js](https://nodejs.org/en/) module available through the
  26. [npm registry](https://www.npmjs.com/). Installation is done using the
  27. [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
  28. ```sh
  29. $ npm install serve-favicon
  30. ```
  31. ## API
  32. ### favicon(path, options)
  33. Create new middleware to serve a favicon from the given `path` to a favicon file.
  34. `path` may also be a `Buffer` of the icon to serve.
  35. #### Options
  36. Serve favicon accepts these properties in the options object.
  37. ##### maxAge
  38. The `cache-control` `max-age` directive in `ms`, defaulting to 1 year. This can
  39. also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
  40. module.
  41. ## Examples
  42. Typically this middleware will come very early in your stack (maybe even first)
  43. to avoid processing any other middleware if we already know the request is for
  44. `/favicon.ico`.
  45. ### express
  46. ```javascript
  47. var express = require('express')
  48. var favicon = require('serve-favicon')
  49. var path = require('path')
  50. var app = express()
  51. app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
  52. // Add your routes here, etc.
  53. app.listen(3000)
  54. ```
  55. ### connect
  56. ```javascript
  57. var connect = require('connect')
  58. var favicon = require('serve-favicon')
  59. var path = require('path')
  60. var app = connect()
  61. app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
  62. // Add your middleware here, etc.
  63. app.listen(3000)
  64. ```
  65. ### vanilla http server
  66. This middleware can be used anywhere, even outside express/connect. It takes
  67. `req`, `res`, and `callback`.
  68. ```javascript
  69. var http = require('http')
  70. var favicon = require('serve-favicon')
  71. var finalhandler = require('finalhandler')
  72. var path = require('path')
  73. var _favicon = favicon(path.join(__dirname, 'public', 'favicon.ico'))
  74. var server = http.createServer(function onRequest (req, res) {
  75. var done = finalhandler(req, res)
  76. _favicon(req, res, function onNext (err) {
  77. if (err) return done(err)
  78. // continue to process the request here, etc.
  79. res.statusCode = 404
  80. res.end('oops')
  81. })
  82. })
  83. server.listen(3000)
  84. ```
  85. ## License
  86. [MIT](LICENSE)
  87. [npm-image]: https://img.shields.io/npm/v/serve-favicon.svg
  88. [npm-url]: https://npmjs.org/package/serve-favicon
  89. [travis-image]: https://img.shields.io/travis/expressjs/serve-favicon/master.svg?label=linux
  90. [travis-url]: https://travis-ci.org/expressjs/serve-favicon
  91. [appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-favicon/master.svg?label=windows
  92. [appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-favicon
  93. [coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-favicon.svg
  94. [coveralls-url]: https://coveralls.io/r/expressjs/serve-favicon?branch=master
  95. [downloads-image]: https://img.shields.io/npm/dm/serve-favicon.svg
  96. [downloads-url]: https://npmjs.org/package/serve-favicon