├── .dockerignore ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jsdoc.json ├── .npmignore ├── .npmrc ├── .taprc ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── example ├── example.js ├── favicon.ico └── home.html ├── package.json ├── src ├── favicon.ico └── plugin.js ├── test ├── favicon.ico ├── favicon.test.js └── named-import.test-d.ts └── types ├── .eslintrc.json ├── plugin.d.ts ├── plugin.test-d.ts └── tsconfig.json /.dockerignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .git 4 | .gitignore 5 | 6 | .settings 7 | .classpath 8 | .project 9 | .cache* 10 | .metadata 11 | .worksheet 12 | RemoteSystemsTempFiles/ 13 | Servers/ 14 | 15 | .gradle 16 | bin/ 17 | build/ 18 | /*/build/ 19 | # dist/ 20 | 21 | *.log 22 | *.log.* 23 | *~* 24 | *.bak 25 | *.tmp 26 | *.temp 27 | Thumbs.db 28 | 29 | _old 30 | /dist 31 | # /*.min.js* 32 | 33 | /.vscode 34 | 35 | out/ 36 | tmp/ 37 | temp/ 38 | /target/ 39 | /target-eclipse/ 40 | 41 | .env 42 | .envrc 43 | local.properties 44 | 45 | # *.class 46 | 47 | node_modules 48 | npm-debug.log 49 | 50 | .nyc_output 51 | /coverage 52 | 53 | .dockerignore 54 | Dockerfile 55 | Dockerfile*.* 56 | Jenkinsfile 57 | Jenkinsfile*.* 58 | /jenkins 59 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | trim_trailing_whitespace = true 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behavior to automatically convert line endings 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # mac files 2 | .DS_Store 3 | 4 | # environment variables file 5 | .env 6 | .envrc 7 | 8 | # IDE/editors 9 | .vscode 10 | .cache 11 | .metadata 12 | .settings 13 | .idea 14 | 15 | # Optional npm cache directory 16 | .npm 17 | 18 | # Optional REPL history 19 | .node_repl_history 20 | 21 | # Optional eslint cache 22 | .eslintcache 23 | 24 | # TypeScript cache 25 | *.tsbuildinfo 26 | 27 | # Yarn Integrity file 28 | .yarn-integrity 29 | 30 | # Clinic analysis/results 31 | profile* 32 | *clinic* 33 | *flamegraph* 34 | 35 | # Logs 36 | logs 37 | *.log 38 | npm-debug.log* 39 | yarn-debug.log* 40 | yarn-error.log* 41 | 42 | # Runtime data 43 | pids 44 | *.pid 45 | *.seed 46 | *.pid.lock 47 | 48 | # Directory for instrumented libs generated by jscoverage/JSCover 49 | lib-cov 50 | 51 | # Coverage directory used by tools like istanbul 52 | coverage 53 | 54 | # nyc test coverage 55 | .nyc_output 56 | 57 | # tap files 58 | .tap/ 59 | 60 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 61 | .grunt 62 | 63 | # Bower dependency directory (https://bower.io/) 64 | bower_components 65 | 66 | # node-waf configuration 67 | .lock-wscript 68 | 69 | # Compiled binary addons (http://nodejs.org/api/addons.html) 70 | build/Release 71 | 72 | # Dependency directories 73 | node_modules/ 74 | jspm_packages/ 75 | 76 | # Snowpack dependency directory 77 | web_modules/ 78 | 79 | # Output of 'npm pack' 80 | *.tgz 81 | 82 | # vim swap files 83 | *.swp 84 | 85 | # lock files 86 | yarn.lock 87 | package-lock.json 88 | 89 | # common files to not commit 90 | *~* 91 | *.bak 92 | Thumbs.db 93 | *.db 94 | *.zip 95 | *.tar 96 | *.tar.gz 97 | 98 | # temporary/work/output folders 99 | _old/ 100 | bin/ 101 | build/ 102 | docs/ 103 | dist/ 104 | out/ 105 | private/ 106 | temp/ 107 | tmp/ 108 | -------------------------------------------------------------------------------- /.jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": ["./src"], 4 | "exclude": ["./example", "./test", "./lib"], 5 | "includePattern": ".+\\.js(doc|x)?$", 6 | "excludePattern": "(^|\\/|\\\\)_" 7 | }, 8 | "opts": { 9 | "template": "templates/default", 10 | "encoding": "utf8", 11 | "destination": "./docs/", 12 | "recurse": true 13 | }, 14 | "plugins": [ 15 | "plugins/summarize" 16 | ], 17 | "tags": { 18 | "allowUnknownTags": false, 19 | "dictionaries": ["jsdoc"] 20 | }, 21 | "templates": { 22 | "default": { 23 | "includeDate": false 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .vscode 4 | .cache 5 | .metadata 6 | .settings 7 | .idea 8 | 9 | _old/ 10 | build/ 11 | docs/ 12 | lib/ 13 | logs/ 14 | out/ 15 | private/ 16 | tmp/ 17 | temp/ 18 | 19 | coverage/ 20 | .nyc_output 21 | .tap/ 22 | 23 | scripts/ 24 | src/ 25 | test/ 26 | # example/ 27 | 28 | *.zip 29 | *.tar 30 | *.tar.gz 31 | *.tgz 32 | 33 | .env 34 | .envrc 35 | .babelrc 36 | .clinic 37 | .dependabot 38 | .eslintignore 39 | .eslintrc* 40 | .eslintcache 41 | .esdoc.json 42 | .yarn-integrity 43 | .taprc 44 | 45 | .editorconfig 46 | .gitattributes 47 | .travis.yml 48 | 49 | gulpfile.* 50 | jsdoc-conf.* 51 | .jsdoc.json 52 | 53 | jenkins.sh 54 | tslint.json 55 | 56 | *.log 57 | 58 | TODO.* 59 | BUILD.md 60 | 61 | .dockerignore 62 | # Dockerfile 63 | # Dockerfile*.* 64 | Jenkinsfile 65 | Jenkinsfile*.* 66 | /jenkins 67 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | # package-lock=false 2 | -------------------------------------------------------------------------------- /.taprc: -------------------------------------------------------------------------------- 1 | # vim: set filetype=yaml : 2 | 3 | # node-arg: 4 | # - '--allow-natives-syntax' 5 | 6 | # jobs: 1 7 | comments: true 8 | # disable-coverage: true 9 | timeout: 60 10 | # typecheck: true 11 | 12 | include: 13 | - 'test/*.test.js' 14 | # - 'test/**/*.test.js' 15 | # - 'test/**/*.test.cjs' 16 | # - 'test/**/*.test.mjs' 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [5.0.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/5.0.0) (2024-09-21) 4 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/4.3.0...5.0.0) 5 | Summary Changelog: 6 | - Updated requirements to Fastify '^5.0.0' 7 | - Updated all dependencies to latest (for Node.js 20 LTS) 8 | 9 | ## [4.3.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/4.3.0) (2023-02-09) 10 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/4.2.0...4.3.0) 11 | Summary Changelog: 12 | - Updated requirements to Fastify '^4.12.0'; 13 | updated all other dependencies to latest 14 | - Compatibility with TypeScript 4.9 and NodeNext / ESNext 15 | - Ensure all works even with Node.js 18 LTS 16 | 17 | ## [4.2.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/4.2.0) (2022-08-25) 18 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/4.1.0...4.2.0) 19 | Summary Changelog: 20 | - Updated requirements to Fastify '^4.5.2' and Fastify-plugin '^4.2.0' 21 | - Updated all dependencies to latest 22 | - Improved performance (a lot) by caching the favicon, see related plugin option 23 | - Simplified test code 24 | - Ensure all works with latest Node.js 14 LTS and later LTS releases 25 | - Improve JSDoc comments, generated documentation is much better now 26 | 27 | ## [4.1.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/4.1.0) (2022-07-19) 28 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/4.0.0...4.1.0) 29 | Summary Changelog: 30 | - Updated requirements to Fastify '^4.0.1' and Fastify-plugin '^4.0.0' 31 | - Ensure all is good as before 32 | 33 | ## [4.0.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/4.0.0) (2022-06-13) 34 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/3.2.0...4.0.0) 35 | Summary Changelog: 36 | - Updated requirements to Fastify '^4.0.0' 37 | - Updated all dependencies to latest (for Node.js 14 LTS) 38 | - Update and simplified example and test code 39 | - Update documentation from sources with JSDoc 40 | 41 | ## [3.2.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/3.2.0) (2022-06-13) 42 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/3.1.0...3.2.0) 43 | Summary Changelog: 44 | - Updated requirements to Fastify '3.11.0' or higher (but still 3.x) 45 | - Updated all dependencies to latest (for Node.js 10 LTS) 46 | - Update TypeScript types 47 | - Update Copyright year 48 | - Update Tap configuration 49 | - Generate documentation from sources with JSDoc 50 | 51 | ## [3.1.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/3.1.0) (2021-02-10) 52 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/3.0.0...3.1.0) 53 | Summary Changelog: 54 | - Updated all dependencies to latest 55 | - Update TypeScript types 56 | - Update code to more modern JavaScript 57 | - Add option to specify favicon file name 58 | 59 | ## [3.0.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/3.0.0) (2020-07-23) 60 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/2.1.0...3.0.0) 61 | Summary Changelog: 62 | - Updated requirements to Fastify '^3.0.0' (as dev dependency) 63 | - Updated all dependencies to latest 64 | - Update TypeScript types 65 | 66 | ## [2.1.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/2.1.0) (2020-06-01) 67 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/2.0.0...2.1.0) 68 | Summary Changelog: 69 | - Updated requirements to Fastify '^2.12.0' (as dev dependency) 70 | - Updated all dependencies to latest 71 | - Add TypeScript types 72 | 73 | ## [2.0.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/2.0.0) (2019-03-01) 74 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/1.0.0...2.0.0) 75 | Summary Changelog: 76 | - Update requirements to Fastify v2 77 | - Update all dependencies 78 | 79 | ## [1.0.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/1.0.0) (2019-02-27) 80 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.3.2...1.0.0) 81 | Summary Changelog: 82 | - Updated all dependencies 83 | - Note that this release number means that the plugin is stable, 84 | and for Fastify v1 85 | 86 | ## [0.3.2](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.3.2) (2019-02-14) 87 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.3.1...0.3.2) 88 | Summary Changelog: 89 | - Update dependency on 'fastify-plugin' to '^1.5.0' 90 | - Update all dependencies to latest 91 | - Update Tap tests 92 | 93 | ## [0.3.1](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.3.1) (2019-02-03) 94 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.3.0...0.3.1) 95 | Summary Changelog: 96 | - Update dependency on 'fastify-plugin' to '^1.4.0' 97 | - Update all dependencies to latest 98 | - Update Tap tests 99 | 100 | ## [0.3.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.3.0) (2018-11-28) 101 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.2.4...0.3.0) 102 | Summary Changelog: 103 | - Update required Fastify version to '^1.1.0', but stay on 1.x 104 | - Update dependency on 'fastify-plugin' to '^1.2.1' 105 | - Updated plugins 106 | - Updated unit tests and examples to use new Fastify syntax/features 107 | - In examples, listen to '127.0.0.1' and no more to all addresses ('0.0.0.0'), 108 | best practice for examples (unless you need to publish from a container) 109 | - Move plugin main source in a 'src' folder, and even default favicon 110 | 111 | ## [0.2.4](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.2.4) (2018-05-19) 112 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.2.3...0.2.4) 113 | Summary Changelog: 114 | - Like in Fastify and core plugins, change dev dependency from 'request' to 'simple-get' 115 | - Custom path for favicon: add a test to ensure that when is not found the default favicon (bundled with the plugin) is served 116 | 117 | ## [0.2.3](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.2.3) (2018-05-17) 118 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.2.2...0.2.3) 119 | Summary Changelog: 120 | - Custom path for favicon: write a warning in Fastify log when using a custom path is not found (so the default one bundled with the plugin is served) 121 | - Custom path for favicon: update info in README, and add some sample usage in the example 122 | 123 | ## [0.2.2](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.2.2) (2018-05-08) 124 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.2.1...0.2.2) 125 | Summary Changelog: 126 | - Fix typo in README 127 | 128 | ## [0.2.1](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.2.1) (2018-04-15) 129 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.2.0...0.2.1) 130 | Summary Changelog: 131 | - Update dependencies (and cleaned up 'peerDependencies') 132 | - For now stay on Fastify 0.43.x, but note that next release will be for Fastify 1.2.1 or later 133 | 134 | ## [0.2.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.2.0) (2018-03-28) 135 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.1.2...0.2.0) 136 | Summary Changelog: 137 | - Fix Issue#2, 'Custom favicon path', to be able to searching 'favicon.ico' from project root, otherwise returning the default one provided by the plugin; or specify a local path to get it 138 | - Update dependencies (need even to add some 'peerDependencies' as needed by latest release of 'standard' and maybe even other package); for now stay on Fastify 0.43.x or later 139 | 140 | ## [0.1.2](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.1.2) (2018-02-22) 141 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.1.1...0.1.2) 142 | Summary Changelog: 143 | - Small optimization to not calculate path at every request 144 | 145 | ## [0.1.1](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.1.1) (2018-02-21) 146 | [Full Changelog](https://github.com/smartiniOnGitHub/fastify-favicon/compare/0.1.0...0.1.1) 147 | Summary Changelog: 148 | - Fix Issue#1, 'Unable to serve favicon.ico' (when using the plugin from a real project) 149 | 150 | ## [0.1.0](https://github.com/smartiniOnGitHub/fastify-favicon/releases/tag/0.1.0) (2018-02-20) 151 | Summary Changelog: 152 | - First release 153 | - Add Fastify favicon, thanks to Fastify Team for the permission 154 | 155 | ---- 156 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | =============================================================================== 204 | 205 | The following components are licensed under the MIT License: 206 | 207 | 1. The Fastify favicon (https://github.com/fastify/graphics , https://github.com/fastify/website) 208 | designed by [Cosmic Fox](https://www.behance.net/cosmicfox), which is available under a MIT license. 209 | 210 | favicon.ico 211 | 212 | MIT License 213 | 214 | Copyright (c) 2016-2018 The Fastify Team 215 | 216 | The Fastify team members are listed at https://github.com/fastify/fastify#team 217 | and in the README file. 218 | 219 | Permission is hereby granted, free of charge, to any person obtaining a copy 220 | of this software and associated documentation files (the "Software"), to deal 221 | in the Software without restriction, including without limitation the rights 222 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 223 | copies of the Software, and to permit persons to whom the Software is 224 | furnished to do so, subject to the following conditions: 225 | 226 | The above copyright notice and this permission notice shall be included in all 227 | copies or substantial portions of the Software. 228 | 229 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 230 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 231 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 232 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 233 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 234 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 235 | SOFTWARE. 236 | 237 | =============================================================================== 238 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | fastify-favicon 2 | Copyright 2018 Sandro Martini 3 | 4 | This product includes software developed at 5 | [Fastify](https://github.com/fastify). 6 | 7 | This software contains images available as graphic components and documentation for Fastify, 8 | designed by [Cosmic Fox](https://www.behance.net/cosmicfox) 9 | https://github.com/fastify/graphics 10 | https://github.com/fastify/website 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastify-favicon 2 | 3 | [![NPM Version](https://img.shields.io/npm/v/fastify-favicon.svg?style=flat)](https://npmjs.org/package/fastify-favicon/) 4 | [![NPM Downloads](https://img.shields.io/npm/dm/fastify-favicon.svg?style=flat)](https://npmjs.org/package/fastify-favicon/) 5 | [![Code Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) 6 | [![license - APACHE-2.0](https://img.shields.io/npm/l/fastify-favicon.svg)](http://opensource.org/licenses/APACHE-2.0) 7 | 8 | Fastify Plugin to serve the favicon. 9 | 10 | With this plugin, Fastify will have a route configured for favicon (usually `/favicon.ico`) requests. 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const fastify = require('fastify')() 17 | 18 | // example without specifying options, searching favicon.ico from project root, 19 | // otherwise returning a default favicon 20 | fastify.register(require('fastify-favicon')) 21 | // or 22 | // example with custom path (usually relative to project root, but could be absolute), 23 | // and custom name; all options are optional 24 | fastify.register(require('fastify-favicon'), { path: './test', name: 'icon.ico', maxAge: 3600 }) 25 | 26 | fastify.listen({ port: 3000, host: 'localhost' }) 27 | // curl http://127.0.0.1:3000/favicon.ico => returning the image, and no error thrown 28 | ``` 29 | 30 | ## Requirements 31 | 32 | Fastify ^5.0.0 , Node.js 20 LTS (20.9.0) or later. 33 | Note that plugin releases 4.x are for Fastify 4.x, 5.x for Fastify 5.x, etc. 34 | 35 | 36 | ## Sources 37 | 38 | Source code is all inside main repo: 39 | [fastify-favicon](https://github.com/smartiniOnGitHub/fastify-favicon). 40 | 41 | Documentation generated from source code (library API): 42 | [here](https://smartiniongithub.github.io/fastify-favicon/). 43 | 44 | 45 | ## Note 46 | 47 | The plugin exposes a GET handler on the URI `/${name}`; 48 | Fastify default favicon is used by default, but a custom one can be used. 49 | 50 | Plugin options: 51 | - path (default `__dirname`) for the folder containing the icon 52 | - name (default 'favicon.ico') for favicon file name 53 | - maxAge (default 86400) for cache duration in seconds for the image 54 | 55 | 56 | ## Contributing 57 | 58 | 1. Fork it ( https://github.com/smartiniOnGitHub/fastify-favicon/fork ) 59 | 2. Create your feature branch (git checkout -b my-new-feature) 60 | 3. Commit your changes (git commit -am 'Add some feature') 61 | 4. Push to the branch (git push origin my-new-feature) 62 | 5. Create a new Pull Request 63 | 64 | 65 | ## License 66 | 67 | Licensed under [Apache-2.0](./LICENSE). 68 | 69 | ---- 70 | -------------------------------------------------------------------------------- /example/example.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 'use strict' 17 | 18 | const fastify = require('fastify')() 19 | 20 | fastify.register(require('..'), { 21 | // some examples of custom path (optional) 22 | // path: 'test' // relative to project root // ok 23 | // path: './test' // relative to project root // ok 24 | // path: '../fastify-favicon/test' // relative to project root with folder change // ok 25 | // path: '../fastify-favicon/test/' // relative to project root with folder change and final slash // ok 26 | // path: '/test' // absolute but dependent on project root // no, doen't work 27 | // path: '/work/fastify-favicon/test' // absolute (full path) // ok, but not recommended 28 | // path: '../fastify-favicon/test-bad' // example with bad path, to let the plugin write a warning in logs (but logs must be enabled in Fastify options) 29 | }) 30 | 31 | // example to handle a sample home request to serve a static page, optional here 32 | fastify.get('/', function (req, reply) { 33 | const path = require('node:path') 34 | const scriptRelativeFolder = path.join(__dirname, path.sep) 35 | const fs = require('node:fs') 36 | const stream = fs.createReadStream(path.join(scriptRelativeFolder, 'home.html')) 37 | reply.type('text/html; charset=utf-8').send(stream) 38 | }) 39 | 40 | fastify.listen({ port: 3000, host: 'localhost' }, (err, address) => { 41 | if (err) throw err 42 | console.log(`Server listening on '${address}' ...`) 43 | }) 44 | 45 | fastify.ready(() => { 46 | const routes = fastify.printRoutes() 47 | console.log(`Available Routes:\n${routes}`) 48 | }) 49 | -------------------------------------------------------------------------------- /example/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartiniOnGitHub/fastify-favicon/29983d235447e01cadcf29677233582a3bf59119/example/favicon.ico -------------------------------------------------------------------------------- /example/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home - Example pages 6 | 7 | 8 | 9 | 10 |

Welcome to the Home page.

11 |
12 | 13 | Plugin routes to call: 14 | 17 |
18 | 19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fastify-favicon", 3 | "version": "5.0.0", 4 | "description": "Fastify plugin to serve default favicon requests", 5 | "main": "src/plugin", 6 | "types": "types/plugin.d.ts", 7 | "scripts": { 8 | "audit:log": "npm audit > ./temp/audit.log", 9 | "clean:install": "rm -rf ./package-lock.json ./node_modules/", 10 | "dependency:log": "npm list > ./temp/dependencies.log", 11 | "docs:clean": "rm -rf ./docs/*", 12 | "docs:generate": "npx jsdoc -c .jsdoc.json -R README.md", 13 | "docs": "npm run docs:clean && npm run docs:generate", 14 | "example": "node example/example", 15 | "lint:fix": "standard --fix", 16 | "lint:standard": "standard --verbose", 17 | "lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/*.ts", 18 | "lint:typescript:eslint": "eslint -c types/.eslintrc.json types/*.d.ts types/*.test-d.ts", 19 | "lint:typescript:eslint:fix": "eslint -c types/.eslintrc.json types/*.d.ts types/*.test-d.ts --fix", 20 | "lint": "npm run lint:standard && npm run lint:typescript", 21 | "test:clean": "rm -rf .nyc_output/* .tap/* ./coverage/*", 22 | "test:coverage:all": "npm run test:unit -- --coverage-report=text", 23 | "test:coverage": "npm run test:unit -- --coverage-report=html", 24 | "test:types": "tsd", 25 | "test:unit:debug": "tap -T --node-arg=--inspect-brk", 26 | "test:unit:dev": "tap --watch --coverage-report=none", 27 | "test:unit": "tap --allow-incomplete-coverage", 28 | "test": "npm run lint:standard && npm run lint:typescript && npm run test:types && npm run test:unit" 29 | }, 30 | "dependencies": { 31 | "fastify-plugin": "^5.0.0" 32 | }, 33 | "devDependencies": { 34 | "@types/node": "^22.5.5", 35 | "@typescript-eslint/eslint-plugin": "^8.6.0", 36 | "@typescript-eslint/parser": "^8.6.0", 37 | "fastify": "^5.0.0", 38 | "jsdoc": "^4.0.3", 39 | "standard": "^17.1.2", 40 | "tap": "^21.0.1", 41 | "tsd": "^0.31.2", 42 | "typescript": "^5.6.2" 43 | }, 44 | "standard": { 45 | "ignore": [ 46 | "types/*" 47 | ] 48 | }, 49 | "tsd": { 50 | "directory": "types", 51 | "compilerOptions": { 52 | "esModuleInterop": true, 53 | "strict": true 54 | } 55 | }, 56 | "peerDependencies": {}, 57 | "engines": { 58 | "node": ">=20.9.0" 59 | }, 60 | "homepage": "https://github.com/smartiniOnGitHub/fastify-favicon#readme", 61 | "repository": { 62 | "type": "git", 63 | "url": "git+https://github.com/smartiniOnGitHub/fastify-favicon.git" 64 | }, 65 | "bugs": { 66 | "url": "https://github.com/smartiniOnGitHub/fastify-favicon/issues" 67 | }, 68 | "keywords": [ 69 | "fastify", 70 | "plugin", 71 | "favicon" 72 | ], 73 | "author": "Sandro Martini ", 74 | "license": "Apache-2.0" 75 | } 76 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartiniOnGitHub/fastify-favicon/29983d235447e01cadcf29677233582a3bf59119/src/favicon.ico -------------------------------------------------------------------------------- /src/plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 'use strict' 17 | 18 | /** 19 | * Plugin: 20 | * this module exports the plugin as a function. 21 | * @module plugin 22 | */ 23 | 24 | const fp = require('fastify-plugin') 25 | const pn = require('node:path') 26 | const fs = require('node:fs') 27 | 28 | const iconNameDefault = 'favicon.ico' 29 | 30 | /** 31 | * Plugin implementation. 32 | * 33 | * @param {!object} fastify Fastify instance 34 | * @param {!object} options plugin configuration options 35 | * 40 | * @param {!function} done callback, to call as last step 41 | * 42 | * @namespace 43 | */ 44 | function fastifyFavicon (fastify, options, done) { 45 | const { 46 | path = __dirname, 47 | name = iconNameDefault, 48 | maxAge = 86400 49 | } = options 50 | 51 | ensureIsString(path, 'iconPath') 52 | ensureIsString(name, 'iconName') 53 | ensureIsInteger(maxAge, 'maxAge') 54 | 55 | const icon = pn.join(path, name) 56 | 57 | fs.readFile(icon, (err, faviconFile) => { 58 | if (err) { 59 | if (err.code === 'ENOENT') { 60 | done(new Error(`fastify-favicon: ${icon} not found`)) 61 | return 62 | } 63 | 64 | done(new Error(`fastify-favicon: Could not load ${icon}`)) 65 | return 66 | } 67 | 68 | fastify.get(`/${name}`, faviconRequestHandler(faviconFile)) 69 | done() 70 | }) 71 | 72 | /** 73 | * Factory for the request handler for the favicon. 74 | * 75 | * @param {!object} file the icon file to send in the response 76 | * @return {function} the handler function, preconfigured with plugin settings and the file to send 77 | * 78 | * @inner 79 | */ 80 | function faviconRequestHandler (file) { 81 | const cacheHeader = `max-age=${maxAge}` 82 | return function handler (_fastifyRequest, fastifyReply) { 83 | fastifyReply 84 | .header('cache-control', cacheHeader) 85 | .type('image/x-icon') 86 | .send(file) 87 | } 88 | } 89 | } 90 | 91 | // utility functions 92 | 93 | function ensureIsString (arg, name) { 94 | if (arg !== null && typeof arg !== 'string') { 95 | throw new TypeError(`The argument '${name}' must be a string, instead got a '${typeof arg}'`) 96 | } 97 | } 98 | function ensureIsInteger (arg, name) { 99 | if (arg !== null && typeof arg !== 'string' && Number.isFinite(arg) === false && Number.isInteger(arg) === false) { 100 | throw new TypeError(`The argument '${name}' must be an integer`) 101 | } 102 | } 103 | 104 | module.exports = fp(fastifyFavicon, { 105 | fastify: '5.x', 106 | name: 'fastify-favicon' 107 | }) 108 | -------------------------------------------------------------------------------- /test/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartiniOnGitHub/fastify-favicon/29983d235447e01cadcf29677233582a3bf59119/test/favicon.ico -------------------------------------------------------------------------------- /test/favicon.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2024 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 'use strict' 17 | 18 | const test = require('tap').test 19 | const Fastify = require('fastify') 20 | 21 | test('default favicon does not return an error, but a good response (200) and some content', async (t) => { 22 | t.plan(5) 23 | 24 | const defaultPath = './src' 25 | const fastify = Fastify() 26 | t.teardown(() => { fastify.close() }) 27 | 28 | fastify.register(require('..'), { 29 | path: defaultPath, 30 | maxAge: 1337 31 | }) // configure this plugin with its default options 32 | 33 | await fastify.listen({ port: 0 }) 34 | 35 | const response = await fastify.inject({ 36 | method: 'GET', 37 | timeout: 2000, 38 | url: '/favicon.ico' 39 | }) 40 | 41 | t.equal(response.statusCode, 200) 42 | t.equal(response.headers['cache-control'], 'max-age=1337') 43 | t.equal(response.headers['content-type'], 'image/x-icon') 44 | 45 | // add check on file contents, or at least file size ... 46 | const fs = require('node:fs') 47 | const contents = fs.readFileSync(`${defaultPath}/favicon.ico`) 48 | t.ok(contents) 49 | t.strictSame(contents.length, response.body.length) 50 | }) 51 | 52 | test('return a favicon configured in a custom path', async (t) => { 53 | t.plan(5) 54 | 55 | const pathSample = './test' 56 | const fastify = Fastify() 57 | 58 | t.teardown(() => { fastify.close() }) 59 | 60 | await fastify.register(require('../'), { 61 | path: pathSample 62 | }) 63 | 64 | await fastify.listen({ port: 0 }) 65 | 66 | const response = await fastify.inject({ 67 | method: 'GET', 68 | timeout: 2000, 69 | url: '/favicon.ico' 70 | }) 71 | 72 | t.equal(response.statusCode, 200) 73 | t.equal(response.headers['cache-control'], 'max-age=86400') 74 | t.equal(response.headers['content-type'], 'image/x-icon') 75 | 76 | // add check on file contents, or at least file size ... 77 | const fs = require('node:fs') 78 | const contents = fs.readFileSync(`${pathSample}/favicon.ico`) 79 | t.ok(contents) 80 | t.strictSame(contents.length, response.body.length) 81 | }) 82 | -------------------------------------------------------------------------------- /test/named-import.test-d.ts: -------------------------------------------------------------------------------- 1 | import fastify from 'fastify' 2 | // import fastifyFavicon, { FastifyFaviconOptions } from '..' 3 | import fastifyFavicon from '..' 4 | 5 | const app = fastify() 6 | 7 | app.register(fastifyFavicon) 8 | -------------------------------------------------------------------------------- /types/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended", 4 | "plugin:@typescript-eslint/eslint-recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "standard" 7 | ], 8 | "parser": "@typescript-eslint/parser", 9 | "plugins": ["@typescript-eslint"], 10 | "env": { "node": true }, 11 | "parserOptions": { 12 | "ecmaVersion": 6, 13 | "sourceType": "module", 14 | "project": "./types/tsconfig.json", 15 | "createDefaultProgram": true 16 | }, 17 | "rules": { 18 | "no-console": "off", 19 | "@typescript-eslint/indent": ["error", 2], 20 | "semi": ["error", "never"], 21 | "import/export": "off" // this errors on multiple exports (overload interfaces) 22 | }, 23 | "overrides": [ 24 | { 25 | "files": ["*.d.ts","*.test-d.ts"], 26 | "rules": { 27 | "@typescript-eslint/no-explicit-any": "off", 28 | "no-redeclare": "off", 29 | "no-use-before-define": "off" 30 | } 31 | }, 32 | { 33 | "files": ["*.test-d.ts"], 34 | "rules": { 35 | "@typescript-eslint/explicit-function-return-type": "off", 36 | "@typescript-eslint/no-empty-function": "off", 37 | "@typescript-eslint/no-non-null-assertion": "off", 38 | "@typescript-eslint/no-unused-vars": "off", 39 | "no-unused-vars": "off", 40 | "node/handle-callback-err": "off" 41 | }, 42 | "globals": { 43 | "NodeJS": "readonly" 44 | } 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /types/plugin.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // import { FastifyInstance, FastifyPluginCallback, FastifyPluginOptions, FastifyRequest } from 'fastify' 4 | import { FastifyPluginCallback } from 'fastify' 5 | 6 | type FastifyFaviconPlugin = FastifyPluginCallback> 7 | 8 | declare namespace fastifyFavicon { 9 | export interface FastifyFaviconOptions { 10 | /** 11 | * Override the path for the folder containing the favicon (default: '__dirname'). 12 | */ 13 | path?: string 14 | 15 | /** 16 | * Override the name for the file containing the favicon (default: 'favicon.ico'). 17 | */ 18 | name?: string 19 | 20 | /** 21 | * Override the cache duration in seconds for the image (default: 86400). 22 | */ 23 | maxAge?: number 24 | } 25 | 26 | export const fastifyFavicon: FastifyFaviconPlugin 27 | export { fastifyFavicon as default } 28 | } 29 | 30 | declare function fastifyFavicon( 31 | ...params: Parameters 32 | ): ReturnType 33 | 34 | export = fastifyFavicon 35 | -------------------------------------------------------------------------------- /types/plugin.test-d.ts: -------------------------------------------------------------------------------- 1 | import fastify from 'fastify' 2 | import fastifyFavicon, { FastifyFaviconOptions } from '..' 3 | import { expectAssignable } from 'tsd' 4 | 5 | const app = fastify() 6 | const options: FastifyFaviconOptions = { 7 | path: 'blah/blah/blah', 8 | name: 'icon.ico' 9 | } 10 | app.register(fastifyFavicon, options) 11 | 12 | app.listen({ port: 3000 }, (err, address) => { 13 | if (err) throw err 14 | console.log(`Server listening on '${address}' ...`) 15 | }) 16 | 17 | expectAssignable({}) 18 | expectAssignable({ 19 | path: 'blah/blah/blah', 20 | name: 'icon.ico', 21 | maxAge: 1 22 | }) 23 | -------------------------------------------------------------------------------- /types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "checkJs": false, 4 | "esModuleInterop": true, 5 | "lib": [ "ES2023", "DOM" ], 6 | "module": "commonjs", 7 | "moduleResolution": "nodenext", 8 | "noEmit": true, 9 | "noImplicitAny": true, 10 | "preserveConstEnums": true, 11 | "sourceMap": false, 12 | "strict": true, 13 | "strictNullChecks": true, 14 | "target": "ES2023" 15 | }, 16 | "include": [ 17 | "./*.d.ts", 18 | "./*.test-d.ts", 19 | "/types/*.d.ts", 20 | "/types/*.test-d.ts", 21 | "../test/*.test-d.ts" 22 | ] 23 | } 24 | --------------------------------------------------------------------------------