Comparing version 4.24.3 to 4.25.2
@@ -128,7 +128,7 @@ <h1 align="center">Fastify</h1> | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
[type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/) | ||
for [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts). | ||
- [`@fastify/type-provider-typebox`](https://github.com/fastify/fastify-type-provider-typebox) | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
[type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/) | ||
for [Typebox](https://github.com/sinclairzx81/typebox). | ||
@@ -142,2 +142,4 @@ - [`@fastify/under-pressure`](https://github.com/fastify/under-pressure) Measure | ||
rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify. | ||
- [`@fastify/vite`](https://github.com/fastify/fastify-vite) Integration with | ||
[Vite](https://vitejs.dev/), allows for serving SPA/MPA/SSR Vite applications. | ||
- [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket | ||
@@ -150,2 +152,4 @@ support for Fastify. Built upon [ws](https://github.com/websockets/ws). | ||
Alternate Fastify and Next.js integration. | ||
- [`@blastorg/fastify-aws-dynamodb-cache`](https://github.com/blastorg/fastify-aws-dynamodb-cache) | ||
A plugin to help with caching API responses using AWS DynamoDB. | ||
- [`@clerk/fastify`](https://github.com/clerkinc/javascript/tree/main/packages/fastify) | ||
@@ -201,4 +205,9 @@ Add authentication and user management to your Fastify application with Clerk. | ||
A custom compact pino-base prettifier | ||
- [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/packages/fastify-api-reference) | ||
Beautiful OpenAPI/Swagger API references for Fastify | ||
- [`@trubavuong/fastify-seaweedfs`](https://github.com/trubavuong/fastify-seaweedfs) | ||
SeaweedFS for Fastify | ||
- [`apitally`](https://github.com/apitally/nodejs-client) Fastify plugin to | ||
integrate with [Apitally](https://apitally.io), a simple API monitoring & | ||
API key management solution. | ||
- [`apollo-server-fastify`](https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-fastify) | ||
@@ -473,4 +482,2 @@ Run an [Apollo Server](https://github.com/apollographql/apollo-server) to | ||
eliminate thrown errors for `/favicon.ico` requests. | ||
- [`fastify-nodemailer`](https://github.com/lependu/fastify-nodemailer) Plugin | ||
to share [nodemailer](https://nodemailer.com) transporter across Fastify. | ||
- [`fastify-normalize-request-reply`](https://github.com/ericrglass/fastify-normalize-request-reply) | ||
@@ -626,7 +633,7 @@ Plugin to normalize the request and reply to the Express version 4.x request | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
[type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/) | ||
for [@effect/schema](https://github.com/effect-ts/schema). | ||
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod) | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
[type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/) | ||
for [zod](https://github.com/colinhacks/zod). | ||
@@ -637,2 +644,4 @@ - [`fastify-typeorm-plugin`](https://github.com/inthepocket/fastify-typeorm-plugin) | ||
request's `user-agent` header. | ||
- [`fastify-uws`](https://github.com/geut/fastify-uws) A Fastify plugin to | ||
use the web server [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js). | ||
- [`fastify-vhost`](https://github.com/patrickpissurno/fastify-vhost) Proxy | ||
@@ -663,2 +672,5 @@ subdomain HTTP requests to another server (useful if you want to point | ||
for AWS XRay recording. | ||
- [`http-wizard`](https://github.com/flodlc/http-wizard) | ||
Exports a typescript api client for your Fastify api and ensures fullstack type | ||
safety for your project. | ||
- [`i18next-http-middleware`](https://github.com/i18next/i18next-http-middleware#fastify-usage) | ||
@@ -665,0 +677,0 @@ An [i18next](https://www.i18next.com) based i18n (internationalization) |
@@ -181,3 +181,3 @@ <h1 align="center">Fastify</h1> | ||
* @param {FastifyInstance} fastify Encapsulated Fastify Instance | ||
* @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options | ||
* @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options | ||
*/ | ||
@@ -297,3 +297,3 @@ async function routes (fastify, options) { | ||
* @param {FastifyInstance} fastify Encapsulated Fastify Instance | ||
* @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options | ||
* @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options | ||
*/ | ||
@@ -317,3 +317,3 @@ async function dbConnector (fastify, options) { | ||
* @param {FastifyInstance} fastify encapsulated fastify instance | ||
* @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options | ||
* @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options | ||
*/ | ||
@@ -320,0 +320,0 @@ async function routes (fastify, options) { |
@@ -496,4 +496,4 @@ <h1 align="center">Fastify</h1> | ||
const warning = require('process-warning')() | ||
warning.create('FastifyDeprecation', 'FST_ERROR_CODE', 'message') | ||
warning.emit('FST_ERROR_CODE') | ||
warning.create('MyPluginWarning', 'MP_ERROR_CODE', 'message') | ||
warning.emit('MP_ERROR_CODE') | ||
``` | ||
@@ -500,0 +500,0 @@ |
@@ -16,3 +16,3 @@ # Fastify Style Guide | ||
Visit the [contribute](https://www.fastify.io/contribute) page on our website or | ||
Visit the [contribute](https://www.fastify.dev/contribute) page on our website or | ||
read the | ||
@@ -74,3 +74,3 @@ [CONTRIBUTING.md](https://github.com/fastify/fastify/blob/main/CONTRIBUTING.md) | ||
``` | ||
To learn more about hooks, see [Fastify hooks](https://www.fastify.io/docs/latest/Reference/Hooks/). | ||
To learn more about hooks, see [Fastify hooks](https://www.fastify.dev/docs/latest/Reference/Hooks/). | ||
``` | ||
@@ -80,3 +80,3 @@ | ||
>To learn more about hooks, see [Fastify | ||
>hooks](https://www.fastify.io/docs/latest/Reference/Hooks/). | ||
>hooks](https://www.fastify.dev/docs/latest/Reference/Hooks/). | ||
@@ -230,3 +230,3 @@ | ||
// Add clear & brief description | ||
[Fastify Plugins] (https://www.fastify.io/docs/latest/Plugins/) | ||
[Fastify Plugins] (https://www.fastify.dev/docs/latest/Plugins/) | ||
@@ -236,9 +236,9 @@ <!--Less like this --> | ||
// incomplete description | ||
[Fastify] (https://www.fastify.io/docs/latest/Plugins/) | ||
[Fastify] (https://www.fastify.dev/docs/latest/Plugins/) | ||
// Adding title in link brackets | ||
[](https://www.fastify.io/docs/latest/Plugins/ "fastify plugin") | ||
[](https://www.fastify.dev/docs/latest/Plugins/ "fastify plugin") | ||
// Empty title | ||
[](https://www.fastify.io/docs/latest/Plugins/) | ||
[](https://www.fastify.dev/docs/latest/Plugins/) | ||
@@ -245,0 +245,0 @@ // Adding links localhost URLs instead of using code strings (``) |
@@ -7,2 +7,4 @@ <h1 align="center">Fastify</h1> | ||
`FST_ERR_CTP_INVALID_MEDIA_TYPE` error will be thrown. | ||
Other common content types are supported through the use of | ||
[plugins](https://fastify.dev/ecosystem/). | ||
@@ -9,0 +11,0 @@ The default charset is `utf-8`. If you need to support different content types, |
@@ -6,2 +6,91 @@ <h1 align="center">Fastify</h1> | ||
**Table of contents** | ||
- [Errors](#errors) | ||
- [Error Handling In Node.js](#error-handling-in-node.js) | ||
- [Uncaught Errors](#uncaught-errors) | ||
- [Catching Errors In Promises](#catching-errors-in-promises) | ||
- [Errors In Fastify](#errors-in-fastify) | ||
- [Errors In Input Data](#errors-in-input-data) | ||
- [Catching Uncaught Errors In Fastify](#catching-uncaught-errors-in-fastify) | ||
- [Errors In Fastify Lifecycle Hooks And A Custom Error Handler](#errors-in-fastify-lifecycle-hooks-and-a-custom-error-handler) | ||
- [Fastify Error Codes](#fastify-error-codes) | ||
- [FST_ERR_NOT_FOUND](#fst_err_not_found) | ||
- [FST_ERR_OPTIONS_NOT_OBJ](#fst_err_options_not_obj) | ||
- [FST_ERR_QSP_NOT_FN](#fst_err_qsp_not_fn) | ||
- [FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN](#fst_err_schema_controller_bucket_opt_not_fn) | ||
- [FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN](#fst_err_schema_error_formatter_not_fn) | ||
- [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ](#fst_err_ajv_custom_options_opt_not_obj) | ||
- [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR](#fst_err_ajv_custom_options_opt_not_arr) | ||
- [FST_ERR_VERSION_CONSTRAINT_NOT_STR](#fst_err_version_constraint_not_str) | ||
- [FST_ERR_CTP_ALREADY_PRESENT](#fst_err_ctp_already_present) | ||
- [FST_ERR_CTP_INVALID_TYPE](#fst_err_ctp_invalid_type) | ||
- [FST_ERR_CTP_EMPTY_TYPE](#fst_err_ctp_empty_type) | ||
- [FST_ERR_CTP_INVALID_HANDLER](#fst_err_ctp_invalid_handler) | ||
- [FST_ERR_CTP_INVALID_PARSE_TYPE](#fst_err_ctp_invalid_parse_type) | ||
- [FST_ERR_CTP_BODY_TOO_LARGE](#fst_err_ctp_body_too_large) | ||
- [FST_ERR_CTP_INVALID_MEDIA_TYPE](#fst_err_ctp_invalid_media_type) | ||
- [FST_ERR_CTP_INVALID_CONTENT_LENGTH](#fst_err_ctp_invalid_content_length) | ||
- [FST_ERR_CTP_EMPTY_JSON_BODY](#fst_err_ctp_empty_json_body) | ||
- [FST_ERR_CTP_INSTANCE_ALREADY_STARTED](#fst_err_ctp_instance_already_started) | ||
- [FST_ERR_INSTANCE_ALREADY_LISTENING](#fst_err_instance_already_listening) | ||
- [FST_ERR_DEC_ALREADY_PRESENT](#fst_err_dec_already_present) | ||
- [FST_ERR_DEC_DEPENDENCY_INVALID_TYPE](#fst_err_dec_dependency_invalid_type) | ||
- [FST_ERR_DEC_MISSING_DEPENDENCY](#fst_err_dec_missing_dependency) | ||
- [FST_ERR_DEC_AFTER_START](#fst_err_dec_after_start) | ||
- [FST_ERR_HOOK_INVALID_TYPE](#fst_err_hook_invalid_type) | ||
- [FST_ERR_HOOK_INVALID_HANDLER](#fst_err_hook_invalid_handler) | ||
- [FST_ERR_HOOK_INVALID_ASYNC_HANDLER](#fst_err_hook_invalid_async_handler) | ||
- [FST_ERR_HOOK_NOT_SUPPORTED](#fst_err_hook_not_supported) | ||
- [FST_ERR_MISSING_MIDDLEWARE](#fst_err_missing_middleware) | ||
- [FST_ERR_HOOK_TIMEOUT](#fst_err_hook_timeout) | ||
- [FST_ERR_LOG_INVALID_DESTINATION](#fst_err_log_invalid_destination) | ||
- [FST_ERR_LOG_INVALID_LOGGER](#fst_err_log_invalid_logger) | ||
- [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type) | ||
- [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent) | ||
- [FST_ERR_REP_SENT_VALUE](#fst_err_rep_sent_value) | ||
- [FST_ERR_SEND_INSIDE_ONERR](#fst_err_send_inside_onerr) | ||
- [FST_ERR_SEND_UNDEFINED_ERR](#fst_err_send_undefined_err) | ||
- [FST_ERR_BAD_STATUS_CODE](#fst_err_bad_status_code) | ||
- [FST_ERR_BAD_TRAILER_NAME](#fst_err_bad_trailer_name) | ||
- [FST_ERR_BAD_TRAILER_VALUE](#fst_err_bad_trailer_value) | ||
- [FST_ERR_FAILED_ERROR_SERIALIZATION](#fst_err_failed_error_serialization) | ||
- [FST_ERR_MISSING_SERIALIZATION_FN](#fst_err_missing_serialization_fn) | ||
- [FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN](#fst_err_missing_contenttype_serialization_fn) | ||
- [FST_ERR_REQ_INVALID_VALIDATION_INVOCATION](#fst_err_req_invalid_validation_invocation) | ||
- [FST_ERR_SCH_MISSING_ID](#fst_err_sch_missing_id) | ||
- [FST_ERR_SCH_ALREADY_PRESENT](#fst_err_sch_already_present) | ||
- [FST_ERR_SCH_CONTENT_MISSING_SCHEMA](#fst_err_sch_content_missing_schema) | ||
- [FST_ERR_SCH_DUPLICATE](#fst_err_sch_duplicate) | ||
- [FST_ERR_SCH_VALIDATION_BUILD](#fst_err_sch_validation_build) | ||
- [FST_ERR_SCH_SERIALIZATION_BUILD](#fst_err_sch_serialization_build) | ||
- [FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX](#fst_err_sch_response_schema_not_nested_2xx) | ||
- [FST_ERR_HTTP2_INVALID_VERSION](#fst_err_http2_invalid_version) | ||
- [FST_ERR_INIT_OPTS_INVALID](#fst_err_init_opts_invalid) | ||
- [FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE](#fst_err_force_close_connections_idle_not_available) | ||
- [FST_ERR_DUPLICATED_ROUTE](#fst_err_duplicated_route) | ||
- [FST_ERR_BAD_URL](#fst_err_bad_url) | ||
- [FST_ERR_ASYNC_CONSTRAINT](#fst_err_async_constraint) | ||
- [FST_ERR_DEFAULT_ROUTE_INVALID_TYPE](#fst_err_default_route_invalid_type) | ||
- [FST_ERR_INVALID_URL](#fst_err_invalid_url) | ||
- [FST_ERR_ROUTE_OPTIONS_NOT_OBJ](#fst_err_route_options_not_obj) | ||
- [FST_ERR_ROUTE_DUPLICATED_HANDLER](#fst_err_route_duplicated_handler) | ||
- [FST_ERR_ROUTE_HANDLER_NOT_FN](#fst_err_route_handler_not_fn) | ||
- [FST_ERR_ROUTE_MISSING_HANDLER](#fst_err_route_missing_handler) | ||
- [FST_ERR_ROUTE_METHOD_INVALID](#fst_err_route_method_invalid) | ||
- [FST_ERR_ROUTE_METHOD_NOT_SUPPORTED](#fst_err_route_method_not_supported) | ||
- [FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED](#fst_err_route_body_validation_schema_not_supported) | ||
- [FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT](#fst_err_route_body_limit_option_not_int) | ||
- [FST_ERR_ROUTE_REWRITE_NOT_STR](#fst_err_route_rewrite_not_str) | ||
- [FST_ERR_REOPENED_CLOSE_SERVER](#fst_err_reopened_close_server) | ||
- [FST_ERR_REOPENED_SERVER](#fst_err_reopened_server) | ||
- [FST_ERR_PLUGIN_VERSION_MISMATCH](#fst_err_plugin_version_mismatch) | ||
- [FST_ERR_PLUGIN_CALLBACK_NOT_FN](#fst_err_plugin_callback_not_fn) | ||
- [FST_ERR_PLUGIN_NOT_VALID](#fst_err_plugin_not_valid) | ||
- [FST_ERR_ROOT_PLG_BOOTED](#fst_err_root_plg_booted) | ||
- [FST_ERR_PARENT_PLUGIN_BOOTED](#fst_err_parent_plugin_booted) | ||
- [FST_ERR_PLUGIN_TIMEOUT](#fst_err_plugin_timeout) | ||
- [FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE](#fst_err_plugin_not_present_in_instance) | ||
- [FST_ERR_VALIDATION](#fst_err_validation) | ||
- [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid) | ||
### Error Handling In Node.js | ||
@@ -132,399 +221,84 @@ <a id="error-handling"></a> | ||
#### FST_ERR_NOT_FOUND | ||
<a id="FST_ERR_NOT_FOUND"></a> | ||
Below is a table with all the error codes that Fastify uses. | ||
404 Not Found. | ||
| Code | Description | How to solve | Discussion | | ||
|------|-------------|--------------|------------| | ||
| <a id="fst_err_not_found">FST_ERR_NOT_FOUND</a> | 404 Not Found | - | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_options_not_obj">FST_ERR_OPTIONS_NOT_OBJ</a> | Fastify options wrongly specified. | Fastify options should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_qsp_not_fn">FST_ERR_QSP_NOT_FN</a> | QueryStringParser wrongly specified. | QueryStringParser option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_schema_controller_bucket_opt_not_fn">FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN</a> | SchemaController.bucket wrongly specified. | SchemaController.bucket option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_schema_error_formatter_not_fn">FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN</a> | SchemaErrorFormatter option wrongly specified. | SchemaErrorFormatter option should be a non async function. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_ajv_custom_options_opt_not_obj">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ</a> | ajv.customOptions wrongly specified. | ajv.customOptions option should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_ajv_custom_options_opt_not_arr">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR</a> | ajv.plugins option wrongly specified. | ajv.plugins option should be an array. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_version_constraint_not_str">FST_ERR_VERSION_CONSTRAINT_NOT_STR</a> | Version constraint wrongly specified. | Version constraint should be a string. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_ctp_already_present">FST_ERR_CTP_ALREADY_PRESENT</a> | The parser for this content type was already registered. | Use a different content type or delete the already registered parser. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_invalid_type">FST_ERR_CTP_INVALID_TYPE</a> | `Content-Type` wrongly specified | The `Content-Type` should be a string. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_empty_type">FST_ERR_CTP_EMPTY_TYPE</a> | `Content-Type` is an empty string. | `Content-Type` cannot be an empty string. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_invalid_handler">FST_ERR_CTP_INVALID_HANDLER</a> | Invalid handler for the content type. | Use a different handler. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_invalid_parse_type">FST_ERR_CTP_INVALID_PARSE_TYPE</a> | The provided parse type is not supported. | Accepted values are <code>string</code> or <code>buffer</code>. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_body_too_large">FST_ERR_CTP_BODY_TOO_LARGE</a> | The request body is larger than the provided limit. | Increase the limit in the Fastify server instance setting: [bodyLimit](./Server.md#bodylimit) | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_invalid_media_type">FST_ERR_CTP_INVALID_MEDIA_TYPE</a> | The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it). | Use a different content type. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_invalid_content_length">FST_ERR_CTP_INVALID_CONTENT_LENGTH</a> | Request body size did not match <code>Content-Length</code>. | Check the request body size and the <code>Content-Length</code> header. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_ctp_empty_json_body">FST_ERR_CTP_EMPTY_JSON_BODY</a> | Body cannot be empty when content-type is set to <code>application/json</code>. | Check the request body. | [#1253](https://github.com/fastify/fastify/pull/1253) | | ||
| <a id="fst_err_ctp_instance_already_started">FST_ERR_CTP_INSTANCE_ALREADY_STARTED</a> | Fastify is already started. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_instance_already_listening">FST_ERR_INSTANCE_ALREADY_LISTENING</a> | Fastify instance is already listening. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_dec_already_present">FST_ERR_DEC_ALREADY_PRESENT</a> | A decorator with the same name is already registered. | Use a different decorator name. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_dec_dependency_invalid_type">FST_ERR_DEC_DEPENDENCY_INVALID_TYPE</a> | The dependencies of decorator must be of type `Array`. | Use an array for the dependencies. | [#3090](https://github.com/fastify/fastify/pull/3090) | | ||
| <a id="fst_err_dec_missing_dependency">FST_ERR_DEC_MISSING_DEPENDENCY</a> | The decorator cannot be registered due to a missing dependency. | Register the missing dependency. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_dec_after_start">FST_ERR_DEC_AFTER_START</a> | The decorator cannot be added after start. | Add the decorator before starting the server. | [#2128](https://github.com/fastify/fastify/pull/2128) | | ||
| <a id="fst_err_hook_invalid_type">FST_ERR_HOOK_INVALID_TYPE</a> | The hook name must be a string. | Use a string for the hook name. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_hook_invalid_handler">FST_ERR_HOOK_INVALID_HANDLER</a> | The hook callback must be a function. | Use a function for the hook callback. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_hook_invalid_async_handler">FST_ERR_HOOK_INVALID_ASYNC_HANDLER</a> | Async function has too many arguments. Async hooks should not use the `done` argument. | Remove the `done` argument from the async hook. | [#4367](https://github.com/fastify/fastify/pull/4367) | | ||
| <a id="fst_err_hook_not_supported">FST_ERR_HOOK_NOT_SUPPORTED</a> | The hook is not supported. | Use a supported hook. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_missing_middleware">FST_ERR_MISSING_MIDDLEWARE</a> | You must register a plugin for handling middlewares, visit [`Middleware`](./Middleware.md) for more info. | Register a plugin for handling middlewares. | [#2014](https://github.com/fastify/fastify/pull/2014) | | ||
| <a id="fst_err_hook_timeout">FST_ERR_HOOK_TIMEOUT</a> | A callback for a hook timed out. | Increase the timeout for the hook. | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_log_invalid_destination">FST_ERR_LOG_INVALID_DESTINATION</a> | The logger does not accept the specified destination. | Use a `'stream'` or a `'file'` as the destination. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_log_invalid_logger">FST_ERR_LOG_INVALID_LOGGER</a> | The logger should have all these methods: `'info'`, `'error'`, `'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. | Use a logger with all the required methods. | [#4520](https://github.com/fastify/fastify/pull/4520) | | ||
| <a id="fst_err_rep_invalid_payload_type">FST_ERR_REP_INVALID_PAYLOAD_TYPE</a> | Reply payload can be either a `string` or a `Buffer`. | Use a `string` or a `Buffer` for the payload. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_rep_already_sent">FST_ERR_REP_ALREADY_SENT</a> | A response was already sent. | - | [#1336](https://github.com/fastify/fastify/pull/1336) | | ||
| <a id="fst_err_rep_sent_value">FST_ERR_REP_SENT_VALUE</a> | The only possible value for `reply.sent` is `true`. | - | [#1336](https://github.com/fastify/fastify/pull/1336) | | ||
| <a id="fst_err_send_inside_onerr">FST_ERR_SEND_INSIDE_ONERR</a> | You cannot use `send` inside the `onError` hook. | - | [#1348](https://github.com/fastify/fastify/pull/1348) | | ||
| <a id="fst_err_send_undefined_err">FST_ERR_SEND_UNDEFINED_ERR</a> | Undefined error has occurred. | - | [#2074](https://github.com/fastify/fastify/pull/2074) | | ||
| <a id="fst_err_bad_status_code">FST_ERR_BAD_STATUS_CODE</a> | The status code is not valid. | Use a valid status code. | [#2082](https://github.com/fastify/fastify/pull/2082) | | ||
| <a id="fst_err_bad_trailer_name">FST_ERR_BAD_TRAILER_NAME</a> | Called `reply.trailer` with an invalid header name. | Use a valid header name. | [#3794](https://github.com/fastify/fastify/pull/3794) | | ||
| <a id="fst_err_bad_trailer_value">FST_ERR_BAD_TRAILER_VALUE</a> | Called `reply.trailer` with an invalid type. Expected a function. | Use a function. | [#3794](https://github.com/fastify/fastify/pull/3794) | | ||
| <a id="fst_err_failed_error_serialization">FST_ERR_FAILED_ERROR_SERIALIZATION</a> | Failed to serialize an error. | - | [#4601](https://github.com/fastify/fastify/pull/4601) | | ||
| <a id="fst_err_missing_serialization_fn">FST_ERR_MISSING_SERIALIZATION_FN</a> | Missing serialization function. | Add a serialization function. | [#3970](https://github.com/fastify/fastify/pull/3970) | | ||
| <a id="fst_err_missing_contenttype_serialization_fn">FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN</a> | Missing `Content-Type` serialization function. | Add a serialization function. | [#4264](https://github.com/fastify/fastify/pull/4264) | | ||
| <a id="fst_err_req_invalid_validation_invocation">FST_ERR_REQ_INVALID_VALIDATION_INVOCATION</a> | Invalid validation invocation. Missing validation function for HTTP part nor schema provided. | Add a validation function. | [#3970](https://github.com/fastify/fastify/pull/3970) | | ||
| <a id="fst_err_sch_missing_id">FST_ERR_SCH_MISSING_ID</a> | The schema provided does not have `$id` property. | Add a `$id` property. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_sch_already_present">FST_ERR_SCH_ALREADY_PRESENT</a> | A schema with the same `$id` already exists. | Use a different `$id`. | [#1168](https://github.com/fastify/fastify/pull/1168) | | ||
| <a id="fst_err_sch_content_missing_schema">FST_ERR_SCH_CONTENT_MISSING_SCHEMA</a> | A schema is missing for the corresponding content type. | Add a schema. | [#4264](https://github.com/fastify/fastify/pull/4264) | | ||
| <a id="fst_err_sch_duplicate">FST_ERR_SCH_DUPLICATE</a> | Schema with the same attribute already present! | Use a different attribute. | [#1954](https://github.com/fastify/fastify/pull/1954) | | ||
| <a id="fst_err_sch_validation_build">FST_ERR_SCH_VALIDATION_BUILD</a> | The JSON schema provided for validation to a route is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) | | ||
| <a id="fst_err_sch_serialization_build">FST_ERR_SCH_SERIALIZATION_BUILD</a> | The JSON schema provided for serialization of a route response is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) | | ||
| <a id="fst_err_sch_response_schema_not_nested_2xx">FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX</a> | Response schemas should be nested under a valid status code (2XX). | Use a valid status code. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_http2_invalid_version">FST_ERR_HTTP2_INVALID_VERSION</a> | HTTP2 is available only from node >= 8.8.1. | Use a higher version of node. | [#1346](https://github.com/fastify/fastify/pull/1346) | | ||
| <a id="fst_err_init_opts_invalid">FST_ERR_INIT_OPTS_INVALID</a> | Invalid initialization options. | Use valid initialization options. | [#1471](https://github.com/fastify/fastify/pull/1471) | | ||
| <a id="fst_err_force_close_connections_idle_not_available">FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE</a> | Cannot set forceCloseConnections to `idle` as your HTTP server does not support `closeIdleConnections` method. | Use a different value for `forceCloseConnections`. | [#3925](https://github.com/fastify/fastify/pull/3925) | | ||
| <a id="fst_err_duplicated_route">FST_ERR_DUPLICATED_ROUTE</a> | The HTTP method already has a registered controller for that URL. | Use a different URL or register the controller for another HTTP method. | [#2954](https://github.com/fastify/fastify/pull/2954) | | ||
| <a id="fst_err_bad_url">FST_ERR_BAD_URL</a> | The router received an invalid url. | Use a valid URL. | [#2106](https://github.com/fastify/fastify/pull/2106) | | ||
| <a id="fst_err_async_constraint">FST_ERR_ASYNC_CONSTRAINT</a> | The router received an error when using asynchronous constraints. | - | [#4323](https://github.com/fastify/fastify/pull/4323) | | ||
| <a id="fst_err_default_route_invalid_type">FST_ERR_DEFAULT_ROUTE_INVALID_TYPE</a> | The `defaultRoute` type should be a function. | Use a function for the `defaultRoute`. | [#2733](https://github.com/fastify/fastify/pull/2733) | | ||
| <a id="fst_err_invalid_url">FST_ERR_INVALID_URL</a> | URL must be a string. | Use a string for the URL. | [#3653](https://github.com/fastify/fastify/pull/3653) | | ||
| <a id="fst_err_route_options_not_obj">FST_ERR_ROUTE_OPTIONS_NOT_OBJ</a> | Options for the route must be an object. | Use an object for the route options. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_duplicated_handler">FST_ERR_ROUTE_DUPLICATED_HANDLER</a> | Duplicate handler for the route is not allowed. | Use a different handler. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_handler_not_fn">FST_ERR_ROUTE_HANDLER_NOT_FN</a> | Handler for the route must be a function. | Use a function for the handler. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_missing_handler">FST_ERR_ROUTE_MISSING_HANDLER</a> | Missing handler function for the route. | Add a handler function. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_method_invalid">FST_ERR_ROUTE_METHOD_INVALID</a> | Method is not a valid value. | Use a valid value for the method. | [#4750](https://github.com/fastify/fastify/pull/4750) | | ||
| <a id="fst_err_route_method_not_supported">FST_ERR_ROUTE_METHOD_NOT_SUPPORTED</a> | Method is not supported for the route. | Use a supported method. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_body_validation_schema_not_supported">FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED</a> | Body validation schema route is not supported. | Use a different different method for the route. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_body_limit_option_not_int">FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT</a> | `bodyLimit` option must be an integer. | Use an integer for the `bodyLimit` option. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_route_rewrite_not_str">FST_ERR_ROUTE_REWRITE_NOT_STR</a> | `rewriteUrl` needs to be of type `string`. | Use a string for the `rewriteUrl`. | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_reopened_close_server">FST_ERR_REOPENED_CLOSE_SERVER</a> | Fastify has already been closed and cannot be reopened. | - | [#2415](https://github.com/fastify/fastify/pull/2415) | | ||
| <a id="fst_err_reopened_server">FST_ERR_REOPENED_SERVER</a> | Fastify is already listening. | - | [#2415](https://github.com/fastify/fastify/pull/2415) | | ||
| <a id="fst_err_plugin_version_mismatch">FST_ERR_PLUGIN_VERSION_MISMATCH</a> | Installed Fastify plugin mismatched expected version. | Use a compatible version of the plugin. | [#2549](https://github.com/fastify/fastify/pull/2549) | | ||
| <a id="fst_err_plugin_callback_not_fn">FST_ERR_PLUGIN_CALLBACK_NOT_FN</a> | Callback for a hook is not a function. | Use a function for the callback. | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_plugin_not_valid">FST_ERR_PLUGIN_NOT_VALID</a> | Plugin must be a function or a promise. | Use a function or a promise for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_root_plg_booted">FST_ERR_ROOT_PLG_BOOTED</a> | Root plugin has already booted. | - | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_parent_plugin_booted">FST_ERR_PARENT_PLUGIN_BOOTED</a> | Impossible to load plugin because the parent (mapped directly from `avvio`) | - | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_plugin_timeout">FST_ERR_PLUGIN_TIMEOUT</a> | Plugin did not start in time. | Increase the timeout for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) | | ||
| <a id="fst_err_plugin_not_present_in_instance">FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE</a> | The decorator is not present in the instance. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | | ||
| <a id="fst_err_validation">FST_ERR_VALIDATION</a> | The Request failed the payload validation. | Check the request payload. | [#4824](https://github.com/fastify/fastify/pull/4824) | | ||
| <a id="fst_err_listen_options_invalid">FST_ERR_LISTEN_OPTIONS_INVALID</a> | Invalid listen options. | Check the listen options. | [#4886](https://github.com/fastify/fastify/pull/4886) | | ||
#### FST_ERR_OPTIONS_NOT_OBJ | ||
<a id="FST_ERR_OPTIONS_NOT_OBJ"></a> | ||
Fastify options must be an object. | ||
#### FST_ERR_QSP_NOT_FN | ||
<a id="FST_ERR_QSP_NOT_FN"></a> | ||
QueryStringParser option should be a function. | ||
#### FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN | ||
<a id="FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN"></a> | ||
SchemaController.bucket option should be a function. | ||
#### FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN | ||
<a id="FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN"></a> | ||
SchemaErrorFormatter option should be a non async function. | ||
#### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ | ||
<a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ"></a> | ||
ajv.customOptions option should be an object. | ||
#### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR | ||
<a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR"></a> | ||
ajv.plugins option should be an array. | ||
#### FST_ERR_VERSION_CONSTRAINT_NOT_STR | ||
<a id="FST_ERR_VERSION_CONSTRAINT_NOT_STR"></a> | ||
Version constraint should be a string. | ||
#### FST_ERR_CTP_ALREADY_PRESENT | ||
<a id="FST_ERR_CTP_ALREADY_PRESENT"></a> | ||
The parser for this content type was already registered. | ||
#### FST_ERR_CTP_INVALID_TYPE | ||
<a id="FST_ERR_CTP_INVALID_TYPE"></a> | ||
The `Content-Type` should be a string. | ||
#### FST_ERR_CTP_EMPTY_TYPE | ||
<a id="FST_ERR_CTP_EMPTY_TYPE"></a> | ||
The content type cannot be an empty string. | ||
#### FST_ERR_CTP_INVALID_HANDLER | ||
<a id="FST_ERR_CTP_INVALID_HANDLER"></a> | ||
An invalid handler was passed for the content type. | ||
#### FST_ERR_CTP_INVALID_PARSE_TYPE | ||
<a id="FST_ERR_CTP_INVALID_PARSE_TYPE"></a> | ||
The provided parse type is not supported. Accepted values are `string` or | ||
`buffer`. | ||
#### FST_ERR_CTP_BODY_TOO_LARGE | ||
<a id="FST_ERR_CTP_BODY_TOO_LARGE"></a> | ||
The request body is larger than the provided limit. | ||
This setting can be defined in the Fastify server instance: | ||
[`bodyLimit`](./Server.md#bodylimit) | ||
#### FST_ERR_CTP_INVALID_MEDIA_TYPE | ||
<a id="FST_ERR_CTP_INVALID_MEDIA_TYPE"></a> | ||
The received media type is not supported (i.e. there is no suitable | ||
`Content-Type` parser for it). | ||
#### FST_ERR_CTP_INVALID_CONTENT_LENGTH | ||
<a id="FST_ERR_CTP_INVALID_CONTENT_LENGTH"></a> | ||
Request body size did not match `Content-Length`. | ||
#### FST_ERR_CTP_EMPTY_JSON_BODY | ||
<a id="FST_ERR_CTP_EMPTY_JSON_BODY"></a> | ||
Body cannot be empty when content-type is set to `application/json`. | ||
#### FST_ERR_CTP_INSTANCE_ALREADY_STARTED | ||
<a id="FST_ERR_CTP_INSTANCE_ALREADY_STARTED"></a> | ||
Fastify is already started. | ||
#### FST_ERR_INSTANCE_ALREADY_LISTENING | ||
<a id="FST_ERR_INSTANCE_ALREADY_LISTENING"></a> | ||
Fastify instance is already listening. | ||
#### FST_ERR_DEC_ALREADY_PRESENT | ||
<a id="FST_ERR_DEC_ALREADY_PRESENT"></a> | ||
A decorator with the same name is already registered. | ||
#### FST_ERR_DEC_DEPENDENCY_INVALID_TYPE | ||
<a id="FST_ERR_DEC_DEPENDENCY_INVALID_TYPE"></a> | ||
The dependencies of decorator must be of type `Array`. | ||
#### FST_ERR_DEC_MISSING_DEPENDENCY | ||
<a id="FST_ERR_DEC_MISSING_DEPENDENCY"></a> | ||
The decorator cannot be registered due to a missing dependency. | ||
#### FST_ERR_DEC_AFTER_START | ||
<a id="FST_ERR_DEC_AFTER_START"></a> | ||
The decorator cannot be added after start. | ||
#### FST_ERR_HOOK_INVALID_TYPE | ||
<a id="FST_ERR_HOOK_INVALID_TYPE"></a> | ||
The hook name must be a string. | ||
#### FST_ERR_HOOK_INVALID_HANDLER | ||
<a id="FST_ERR_HOOK_INVALID_HANDLER"></a> | ||
The hook callback must be a function. | ||
#### FST_ERR_HOOK_INVALID_ASYNC_HANDLER | ||
<a id="FST_ERR_HOOK_INVALID_ASYNC_HANDLER"></a> | ||
Async function has too many arguments. Async hooks should not use the `done` argument. | ||
#### FST_ERR_HOOK_NOT_SUPPORTED | ||
<a id="FST_ERR_HOOK_NOT_SUPPORTED"></a> | ||
The hook is not supported. | ||
#### FST_ERR_MISSING_MIDDLEWARE | ||
<a id="FST_ERR_MISSING_MIDDLEWARE"></a> | ||
You must register a plugin for handling middlewares, | ||
visit [`Middleware`](./Middleware.md) for more info. | ||
#### FST_ERR_HOOK_TIMEOUT | ||
<a id="FST_ERR_HOOK_TIMEOUT"></a> | ||
A callback for a hook timed out | ||
#### FST_ERR_LOG_INVALID_DESTINATION | ||
<a id="FST_ERR_LOG_INVALID_DESTINATION"></a> | ||
The logger accepts either a `'stream'` or a `'file'` as the destination. | ||
#### FST_ERR_LOG_INVALID_LOGGER | ||
<a id="FST_ERR_LOG_INVALID_LOGGER"></a> | ||
The logger should have all these methods: `'info'`, `'error'`, | ||
`'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. | ||
#### FST_ERR_REP_INVALID_PAYLOAD_TYPE | ||
<a id="FST_ERR_REP_INVALID_PAYLOAD_TYPE"></a> | ||
Reply payload can be either a `string` or a `Buffer`. | ||
#### FST_ERR_REP_ALREADY_SENT | ||
<a id="FST_ERR_REP_ALREADY_SENT"></a> | ||
A response was already sent. | ||
#### FST_ERR_REP_SENT_VALUE | ||
<a id="FST_ERR_REP_SENT_VALUE"></a> | ||
The only possible value for `reply.sent` is `true`. | ||
#### FST_ERR_SEND_INSIDE_ONERR | ||
<a id="FST_ERR_SEND_INSIDE_ONERR"></a> | ||
You cannot use `send` inside the `onError` hook. | ||
#### FST_ERR_SEND_UNDEFINED_ERR | ||
<a id="FST_ERR_SEND_UNDEFINED_ERR"></a> | ||
Undefined error has occurred. | ||
#### FST_ERR_BAD_STATUS_CODE | ||
<a id="FST_ERR_BAD_STATUS_CODE"></a> | ||
Called `reply` with an invalid status code. | ||
#### FST_ERR_BAD_TRAILER_NAME | ||
<a id="FST_ERR_BAD_TRAILER_NAME"></a> | ||
Called `reply.trailer` with an invalid header name. | ||
#### FST_ERR_BAD_TRAILER_VALUE | ||
<a id="FST_ERR_BAD_TRAILER_VALUE"></a> | ||
Called `reply.trailer` with an invalid type. Expected a function. | ||
#### FST_ERR_FAILED_ERROR_SERIALIZATION | ||
<a id="FST_ERR_FAILED_ERROR_SERIALIZATION"></a> | ||
Failed to serialize an error. | ||
#### FST_ERR_MISSING_SERIALIZATION_FN | ||
<a id="FST_ERR_MISSING_SERIALIZATION_FN"></a> | ||
Missing serialization function. | ||
#### FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN | ||
<a id="FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN"></a> | ||
Missing serialization function. | ||
#### FST_ERR_REQ_INVALID_VALIDATION_INVOCATION | ||
<a id="FST_ERR_REQ_INVALID_VALIDATION_INVOCATION"></a> | ||
Invalid validation invocation. Missing validation function for | ||
HTTP part nor schema provided. | ||
#### FST_ERR_SCH_MISSING_ID | ||
<a id="FST_ERR_SCH_MISSING_ID"></a> | ||
The schema provided does not have `$id` property. | ||
#### FST_ERR_SCH_ALREADY_PRESENT | ||
<a id="FST_ERR_SCH_ALREADY_PRESENT"></a> | ||
A schema with the same `$id` already exists. | ||
#### FST_ERR_SCH_CONTENT_MISSING_SCHEMA | ||
<a id="FST_ERR_SCH_CONTENT_MISSING_SCHEMA"></a> | ||
A schema is missing for the corresponding content type. | ||
#### FST_ERR_SCH_DUPLICATE | ||
<a id="FST_ERR_SCH_DUPLICATE"></a> | ||
Schema with the same `$id` already present! | ||
#### FST_ERR_SCH_VALIDATION_BUILD | ||
<a id="FST_ERR_SCH_VALIDATION_BUILD"></a> | ||
The JSON schema provided for validation to a route is not valid. | ||
#### FST_ERR_SCH_SERIALIZATION_BUILD | ||
<a id="FST_ERR_SCH_SERIALIZATION_BUILD"></a> | ||
The JSON schema provided for serialization of a route response is not valid. | ||
#### FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX | ||
<a id="FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX"></a> | ||
Response schemas should be nested under a valid status code (2XX). | ||
#### FST_ERR_HTTP2_INVALID_VERSION | ||
<a id="FST_ERR_HTTP2_INVALID_VERSION"></a> | ||
HTTP2 is available only from node >= 8.8.1. | ||
#### FST_ERR_INIT_OPTS_INVALID | ||
<a id="FST_ERR_INIT_OPTS_INVALID"></a> | ||
Invalid initialization options. | ||
#### FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE | ||
<a id="FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE"></a> | ||
Cannot set forceCloseConnections to `idle` as your HTTP server | ||
does not support `closeIdleConnections` method. | ||
#### FST_ERR_DUPLICATED_ROUTE | ||
<a id="FST_ERR_DUPLICATED_ROUTE"></a> | ||
The HTTP method already has a registered controller for that URL | ||
#### FST_ERR_BAD_URL | ||
<a id="FST_ERR_BAD_URL"></a> | ||
The router received an invalid url. | ||
#### FST_ERR_ASYNC_CONSTRAINT | ||
<a id="FST_ERR_ASYNC_CONSTRAINT"></a> | ||
The router received an error when using asynchronous constraints. | ||
#### FST_ERR_DEFAULT_ROUTE_INVALID_TYPE | ||
<a id="FST_ERR_DEFAULT_ROUTE_INVALID_TYPE"></a> | ||
The `defaultRoute` type should be a function. | ||
#### FST_ERR_INVALID_URL | ||
<a id="FST_ERR_INVALID_URL"></a> | ||
URL must be a string. | ||
#### FST_ERR_ROUTE_OPTIONS_NOT_OBJ | ||
<a id="FST_ERR_ROUTE_OPTIONS_NOT_OBJ"></a> | ||
Options for the route must be an object. | ||
#### FST_ERR_ROUTE_DUPLICATED_HANDLER | ||
<a id="FST_ERR_ROUTE_DUPLICATED_HANDLER"></a> | ||
Duplicate handler for the route is not allowed. | ||
#### FST_ERR_ROUTE_HANDLER_NOT_FN | ||
<a id="FST_ERR_ROUTE_HANDLER_NOT_FN"></a> | ||
Handler for the route must be a function. | ||
#### FST_ERR_ROUTE_MISSING_HANDLER | ||
<a id="FST_ERR_ROUTE_MISSING_HANDLER"></a> | ||
Missing handler function for the route. | ||
#### FST_ERR_ROUTE_METHOD_INVALID | ||
<a id="FST_ERR_ROUTE_METHOD_INVALID"></a> | ||
Method is not a valid value. | ||
#### FST_ERR_ROUTE_METHOD_NOT_SUPPORTED | ||
<a id="FST_ERR_ROUTE_METHOD_NOT_SUPPORTED"></a> | ||
Method is not supported for the route. | ||
#### FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED | ||
<a id="FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED"></a> | ||
Body validation schema route is not supported. | ||
#### FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT | ||
<a id="FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT"></a> | ||
BodyLimit option must be an integer. | ||
#### FST_ERR_ROUTE_REWRITE_NOT_STR | ||
<a id="FST_ERR_ROUTE_REWRITE_NOT_STR"></a> | ||
Rewrite url needs to be of type "string". | ||
#### FST_ERR_REOPENED_CLOSE_SERVER | ||
<a id="FST_ERR_REOPENED_CLOSE_SERVER"></a> | ||
Fastify has already been closed and cannot be reopened. | ||
#### FST_ERR_REOPENED_SERVER | ||
<a id="FST_ERR_REOPENED_SERVER"></a> | ||
Fastify is already listening. | ||
#### FST_ERR_PLUGIN_VERSION_MISMATCH | ||
<a id="FST_ERR_PLUGIN_VERSION_MISMATCH"></a> | ||
Installed Fastify plugin mismatched expected version. | ||
#### FST_ERR_PLUGIN_CALLBACK_NOT_FN | ||
<a id="FST_ERR_PLUGIN_CALLBACK_NOT_FN"></a> | ||
Callback for a hook is not a function (mapped directly from `avvio`) | ||
#### FST_ERR_PLUGIN_NOT_VALID | ||
<a id="FST_ERR_PLUGIN_NOT_VALID"></a> | ||
Plugin must be a function or a promise. | ||
#### FST_ERR_ROOT_PLG_BOOTED | ||
<a id="FST_ERR_ROOT_PLG_BOOTED"></a> | ||
Root plugin has already booted (mapped directly from `avvio`) | ||
#### FST_ERR_PARENT_PLUGIN_BOOTED | ||
<a id="FST_ERR_PARENT_PLUGIN_BOOTED"></a> | ||
Impossible to load plugin because the parent (mapped directly from `avvio`) | ||
#### FST_ERR_PLUGIN_TIMEOUT | ||
<a id="FST_ERR_PLUGIN_TIMEOUT"></a> | ||
Plugin did not start in time. Default timeout (in milliseconds): `10000` | ||
#### FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE | ||
<a id="FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE"></a> | ||
The decorator is not present in the instance. | ||
#### FST_ERR_VALIDATION | ||
<a id="FST_ERR_VALIDATION"></a> | ||
The Request failed the payload validation. | ||
#### FST_ERR_LISTEN_OPTIONS_INVALID | ||
<a id="FST_ERR_LISTEN_OPTIONS_INVALID"></a> | ||
Invalid listen options. |
@@ -133,2 +133,6 @@ <h1 align="center">Fastify</h1> | ||
### preHandler | ||
The `preHandler` hook allows you to specify a function that is executed before | ||
a routes's handler. | ||
```js | ||
@@ -350,5 +354,7 @@ fastify.addHook('preHandler', (request, reply, done) => { | ||
fastify.addHook('preHandler', async (request, reply) => { | ||
await something() | ||
reply.send({ hello: 'world' }) | ||
setTimeout(() => { | ||
reply.send({ hello: 'from prehandler' }) | ||
}) | ||
return reply // mandatory, so the request is not executed further | ||
// Commenting the line above will allow the hooks to continue and fail with FST_ERR_REP_ALREADY_SENT | ||
}) | ||
@@ -355,0 +361,0 @@ ``` |
@@ -72,1 +72,3 @@ <h1 align="center">Fastify</h1> | ||
for responses. | ||
+ [Warnings](./Warnings.md): Details the warnings Fastify emits and how to | ||
solve them. |
@@ -89,3 +89,2 @@ <h1 align="center">Fastify</h1> | ||
- `.context` - Deprecated, access the [Request's context](./Request.md) property. | ||
- `.routeOptions` - Access the [Request's routeOptions](./Request.md) property. | ||
@@ -670,4 +669,8 @@ ```js | ||
*send* can also handle streams by setting the `'Content-Type'` header to | ||
`'application/octet-stream'`. | ||
If you are sending a stream and you have not set a `'Content-Type'` header, | ||
*send* will set it to `'application/octet-stream'`. | ||
As noted above, streams are considered to be pre-serialized, so they will be | ||
sent unmodified without response validation. | ||
```js | ||
@@ -696,2 +699,6 @@ fastify.get('/streams', function (request, reply) { | ||
*send* will set it to `'application/octet-stream'`. | ||
As noted above, Buffers are considered to be pre-serialized, so they will be | ||
sent unmodified without response validation. | ||
```js | ||
@@ -720,4 +727,8 @@ const fs = require('node:fs') | ||
`send` manages TypedArray and sets the `'Content-Type'=application/octet-stream'` | ||
header if not already set. | ||
`send` manages TypedArray like a Buffer, and sets the `'Content-Type'` | ||
header to `'application/octet-stream'` if not already set. | ||
As noted above, TypedArray/Buffers are considered to be pre-serialized, so they | ||
will be sent unmodified without response validation. | ||
```js | ||
@@ -724,0 +735,0 @@ const fs = require('node:fs') |
@@ -164,3 +164,3 @@ <h1 align="center">Fastify</h1> | ||
The function returned (a.k.a. _validation function_) is compiled | ||
by using the provided [`SchemaControler#ValidationCompiler`](./Server.md#schema-controller). | ||
by using the provided [`SchemaController#ValidationCompiler`](./Server.md#schema-controller). | ||
A `WeakMap` is used to cached this, reducing compilation calls. | ||
@@ -167,0 +167,0 @@ |
@@ -718,5 +718,5 @@ <h1 align="center">Fastify</h1> | ||
url: '/', | ||
constraints: { host: 'auth.fastify.io' }, | ||
constraints: { host: 'auth.fastify.dev' }, | ||
handler: function (request, reply) { | ||
reply.send('hello world from auth.fastify.io') | ||
reply.send('hello world from auth.fastify.dev') | ||
} | ||
@@ -739,6 +739,6 @@ }) | ||
headers: { | ||
'Host': 'auth.fastify.io' | ||
'Host': 'auth.fastify.dev' | ||
} | ||
}, (err, res) => { | ||
// => 'hello world from auth.fastify.io' | ||
// => 'hello world from auth.fastify.dev' | ||
}) | ||
@@ -754,3 +754,3 @@ ``` | ||
url: '/', | ||
constraints: { host: /.*\.fastify\.io/ }, // will match any subdomain of fastify.io | ||
constraints: { host: /.*\.fastify\.io/ }, // will match any subdomain of fastify.dev | ||
handler: function (request, reply) { | ||
@@ -757,0 +757,0 @@ reply.send('hello world from ' + request.headers.host) |
@@ -1535,5 +1535,7 @@ <h1 align="center">Fastify</h1> | ||
> **Note** | ||
> `setErrorHandler` will ***not*** catch any error inside | ||
> an `onResponse` hook because the response has already been sent to the client. | ||
`setErrorHandler` will ***not*** catch: | ||
- errors thrown in an `onResponse` hook because the response has already been | ||
sent to the client. Use the `onSend` hook instead. | ||
- not found (404) errors. Use [`setNotFoundHandler`](#set-not-found-handler) | ||
instead. | ||
@@ -1540,0 +1542,0 @@ ```js |
@@ -259,3 +259,3 @@ <h1 align="center">Fastify</h1> | ||
app.post<{ Body: UserType, Reply: UserType }>( | ||
fastify.post<{ Body: UserType, Reply: UserType }>( | ||
'/', | ||
@@ -262,0 +262,0 @@ { |
'use strict' | ||
const VERSION = '4.24.3' | ||
const VERSION = '4.25.2' | ||
@@ -50,3 +50,3 @@ const Avvio = require('avvio') | ||
const override = require('./lib/pluginOverride') | ||
const warning = require('./lib/warnings') | ||
const { FSTDEP009 } = require('./lib/warnings') | ||
const noopSet = require('./lib/noop-set') | ||
@@ -156,3 +156,3 @@ const { | ||
if (options.versioning) { | ||
warning.emit('FSTDEP009') | ||
FSTDEP009() | ||
constraints = { | ||
@@ -222,3 +222,6 @@ ...constraints, | ||
closing: false, | ||
started: false | ||
started: false, | ||
ready: false, | ||
booting: false, | ||
readyPromise: null | ||
}, | ||
@@ -568,2 +571,11 @@ [kKeepAliveConnections]: keepAliveConnections, | ||
function ready (cb) { | ||
if (this[kState].readyPromise !== null) { | ||
if (cb != null) { | ||
this[kState].readyPromise.then(() => cb(null, fastify), cb) | ||
return | ||
} | ||
return this[kState].readyPromise | ||
} | ||
let resolveReady | ||
@@ -575,7 +587,15 @@ let rejectReady | ||
// Create a promise no matter what | ||
// It will work as a barrier for all the .ready() calls (ensuring single hook execution) | ||
// as well as a flow control mechanism to chain cbs and further | ||
// promises | ||
this[kState].readyPromise = new Promise(function (resolve, reject) { | ||
resolveReady = resolve | ||
rejectReady = reject | ||
}) | ||
if (!cb) { | ||
return new Promise(function (resolve, reject) { | ||
resolveReady = resolve | ||
rejectReady = reject | ||
}) | ||
return this[kState].readyPromise | ||
} else { | ||
this[kState].readyPromise.then(() => cb(null, fastify), cb) | ||
} | ||
@@ -586,5 +606,6 @@ | ||
fastify[kAvvioBoot]((err, done) => { | ||
if (err || fastify[kState].started) { | ||
if (err || fastify[kState].started || fastify[kState].ready || fastify[kState].booting) { | ||
manageErr(err) | ||
} else { | ||
fastify[kState].booting = true | ||
hookRunnerApplication('onReady', fastify[kAvvioBoot], fastify, manageErr) | ||
@@ -604,14 +625,10 @@ } | ||
if (cb) { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
cb(undefined, fastify) | ||
} | ||
} else { | ||
if (err) { | ||
return rejectReady(err) | ||
} | ||
resolveReady(fastify) | ||
if (err) { | ||
return rejectReady(err) | ||
} | ||
resolveReady(fastify) | ||
fastify[kState].booting = false | ||
fastify[kState].ready = true | ||
fastify[kState].promise = null | ||
} | ||
@@ -618,0 +635,0 @@ } |
@@ -19,3 +19,3 @@ 'use strict' | ||
const warning = require('./warnings') | ||
const { FSTDEP006 } = require('./warnings') | ||
@@ -62,3 +62,3 @@ function decorate (instance, name, fn, dependencies) { | ||
if (typeof fn === 'object' && fn && !(typeof fn.getter === 'function' || typeof fn.setter === 'function')) { | ||
warning.emit('FSTDEP006', name) | ||
FSTDEP006(name) | ||
} | ||
@@ -65,0 +65,0 @@ } |
@@ -182,3 +182,3 @@ 'use strict' | ||
'FST_ERR_MISSING_MIDDLEWARE', | ||
'You must register a plugin for handling middlewares, visit fastify.io/docs/latest/Reference/Middleware/ for more info.', | ||
'You must register a plugin for handling middlewares, visit fastify.dev/docs/latest/Reference/Middleware/ for more info.', | ||
500 | ||
@@ -185,0 +185,0 @@ ), |
@@ -334,3 +334,3 @@ 'use strict' | ||
if (typeof newPayload !== 'undefined') { | ||
if (newPayload !== undefined) { | ||
request[kRequestPayloadStream] = newPayload | ||
@@ -337,0 +337,0 @@ } |
@@ -14,2 +14,3 @@ 'use strict' | ||
} = require('./errors') | ||
const { FSTWRN002 } = require('./warnings.js') | ||
@@ -136,6 +137,14 @@ function getMeta (fn) { | ||
this[kRegisteredPlugins].push(name) | ||
return name | ||
} | ||
function checkPluginHealthiness (fn, pluginName) { | ||
if (fn.constructor.name === 'AsyncFunction' && fn.length === 3) { | ||
FSTWRN002(pluginName || 'anonymous') | ||
} | ||
} | ||
function registerPlugin (fn) { | ||
registerPluginName.call(this, fn) | ||
const pluginName = registerPluginName.call(this, fn) || getPluginName(fn) | ||
checkPluginHealthiness.call(this, fn, pluginName) | ||
checkVersion.call(this, fn) | ||
@@ -142,0 +151,0 @@ checkDecorators.call(this, fn) |
@@ -56,3 +56,3 @@ 'use strict' | ||
} = require('./errors') | ||
const warning = require('./warnings') | ||
const { FSTDEP010, FSTDEP013, FSTDEP019 } = require('./warnings') | ||
@@ -84,3 +84,3 @@ function Reply (res, request, log) { | ||
get () { | ||
warning.emit('FSTDEP019') | ||
FSTDEP019() | ||
return this.request[kRouteContext] | ||
@@ -101,3 +101,3 @@ } | ||
set (value) { | ||
warning.emit('FSTDEP010') | ||
FSTDEP010() | ||
@@ -170,3 +170,3 @@ if (value !== true) { | ||
} | ||
const payloadToSend = Buffer.isBuffer(payload) ? payload : Buffer.from(payload.buffer) | ||
const payloadToSend = Buffer.isBuffer(payload) ? payload : Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength) | ||
onSendHook(this, payloadToSend) | ||
@@ -612,2 +612,6 @@ return this | ||
sendTrailer(undefined, res, reply) | ||
if (typeof payload.resume === 'function') { | ||
payload.on('error', noop) | ||
payload.resume() | ||
} | ||
return | ||
@@ -756,3 +760,3 @@ } | ||
// TODO: should be removed in fastify@5 | ||
warning.emit('FSTDEP013') | ||
FSTDEP013() | ||
cb(null, result) | ||
@@ -759,0 +763,0 @@ } |
@@ -5,4 +5,11 @@ 'use strict' | ||
const semver = require('semver') | ||
const warning = require('./warnings') | ||
const { | ||
FSTDEP005, | ||
FSTDEP012, | ||
FSTDEP015, | ||
FSTDEP016, | ||
FSTDEP017, | ||
FSTDEP018 | ||
} = require('./warnings') | ||
const { | ||
kHasBeenDecorated, | ||
@@ -170,3 +177,3 @@ kSchemaBody, | ||
get () { | ||
warning.emit('FSTDEP012') | ||
FSTDEP012() | ||
return this[kRouteContext] | ||
@@ -177,3 +184,3 @@ } | ||
get () { | ||
warning.emit('FSTDEP017') | ||
FSTDEP017() | ||
return this[kRouteContext].config?.url | ||
@@ -214,3 +221,3 @@ } | ||
get () { | ||
warning.emit('FSTDEP018') | ||
FSTDEP018() | ||
return this[kRouteContext].config?.method | ||
@@ -221,3 +228,3 @@ } | ||
get () { | ||
warning.emit('FSTDEP016') | ||
FSTDEP016() | ||
return this[kRouteContext][kPublicRouteContext]?.config | ||
@@ -228,3 +235,3 @@ } | ||
get () { | ||
warning.emit('FSTDEP015') | ||
FSTDEP015() | ||
return this[kRouteContext][kPublicRouteContext].schema | ||
@@ -242,3 +249,3 @@ } | ||
if (semver.gte(process.versions.node, '13.0.0')) { | ||
warning.emit('FSTDEP005') | ||
FSTDEP005() | ||
} | ||
@@ -245,0 +252,0 @@ return this.raw.connection |
@@ -10,3 +10,7 @@ 'use strict' | ||
const { parseHeadOnSendHandlers } = require('./headRoute') | ||
const warning = require('./warnings') | ||
const { | ||
FSTDEP007, | ||
FSTDEP008, | ||
FSTDEP014 | ||
} = require('./warnings') | ||
@@ -104,7 +108,7 @@ const { | ||
getDefaultRoute: function () { | ||
warning.emit('FSTDEP014') | ||
FSTDEP014() | ||
return router.defaultRoute | ||
}, | ||
setDefaultRoute: function (defaultRoute) { | ||
warning.emit('FSTDEP014') | ||
FSTDEP014() | ||
if (typeof defaultRoute !== 'function') { | ||
@@ -329,3 +333,3 @@ throw new FST_ERR_DEFAULT_ROUTE_INVALID_TYPE() | ||
if (opts.version) { | ||
warning.emit('FSTDEP008') | ||
FSTDEP008() | ||
constraints.version = opts.version | ||
@@ -423,3 +427,3 @@ } | ||
} else if (hasHEADHandler && exposeHeadRoute) { | ||
warning.emit('FSTDEP007') | ||
FSTDEP007() | ||
} | ||
@@ -426,0 +430,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict' | ||
const warnings = require('./warnings') | ||
const { FSTDEP011 } = require('./warnings') | ||
const { kState, kOptions, kServerBindings } = require('./symbols') | ||
@@ -40,3 +40,3 @@ const { onListenHookRunner } = require('./hooks') | ||
} else if (arguments.length > 0 && (firstArgType !== '[object Object]' && firstArgType !== '[object Function]')) { | ||
warnings.emit('FSTDEP011') | ||
FSTDEP011() | ||
listenOptions = normalizeListenArgs(Array.from(arguments)) | ||
@@ -46,3 +46,3 @@ cb = listenOptions.cb | ||
// `.listen(obj, a, ..., n, callback )` | ||
warnings.emit('FSTDEP011') | ||
FSTDEP011() | ||
// Deal with `.listen(port, host, backlog, [cb])` | ||
@@ -169,25 +169,2 @@ const hostPath = listenOptions.path ? [listenOptions.path] : [listenOptions.port ?? 0, listenOptions.host ?? 'localhost'] | ||
this[kServerBindings].push(secondaryServer) | ||
// Due to the nature of the feature is not possible to know | ||
// ahead of time the number of bindings that will be made. | ||
// For instance, each binding is hooked to be closed at their own | ||
// pace through the `onClose` hook. | ||
// It also allows them to handle possible connections already | ||
// attached to them if any. | ||
/* c8 ignore next 20 */ | ||
this.onClose((instance, done) => { | ||
if (instance[kState].listening) { | ||
// No new TCP connections are accepted | ||
// We swallow any error from the secondary | ||
// server | ||
secondaryServer.close(() => done()) | ||
if (serverOpts.forceCloseConnections === 'idle') { | ||
// Not needed in Node 19 | ||
secondaryServer.closeIdleConnections() | ||
} else if (typeof secondaryServer.closeAllConnections === 'function' && serverOpts.forceCloseConnections) { | ||
secondaryServer.closeAllConnections() | ||
} | ||
} else { | ||
done() | ||
} | ||
}) | ||
} | ||
@@ -203,3 +180,19 @@ | ||
const secondaryServer = getServerInstance(serverOpts, httpHandler) | ||
const closeSecondary = () => { secondaryServer.close(() => { }) } | ||
const closeSecondary = () => { | ||
// To avoid fall into situations where the close of the | ||
// secondary server is triggered before the preClose hook | ||
// is done running, we better wait until the main server | ||
// is closed. | ||
// No new TCP connections are accepted | ||
// We swallow any error from the secondary | ||
// server | ||
secondaryServer.close(() => {}) | ||
if (serverOpts.forceCloseConnections === 'idle') { | ||
// Not needed in Node 19 | ||
secondaryServer.closeIdleConnections() | ||
} else if (typeof secondaryServer.closeAllConnections === 'function' && serverOpts.forceCloseConnections) { | ||
secondaryServer.closeAllConnections() | ||
} | ||
} | ||
secondaryServer.on('upgrade', mainServer.emit.bind(mainServer, 'upgrade')) | ||
@@ -206,0 +199,0 @@ mainServer.on('unref', closeSecondary) |
@@ -16,3 +16,3 @@ 'use strict' | ||
const warning = require('./warnings') | ||
const { FSTWRN001 } = require('./warnings') | ||
@@ -87,3 +87,3 @@ function compileSchemasForSerialization (context, compile) { | ||
} else if (Object.prototype.hasOwnProperty.call(schema, 'headers')) { | ||
warning.emit('FSTWRN001', 'headers', method, url) | ||
FSTWRN001('headers', method, url) | ||
} | ||
@@ -94,3 +94,3 @@ | ||
} else if (Object.prototype.hasOwnProperty.call(schema, 'body')) { | ||
warning.emit('FSTWRN001', 'body', method, url) | ||
FSTWRN001('body', method, url) | ||
} | ||
@@ -101,3 +101,3 @@ | ||
} else if (Object.prototype.hasOwnProperty.call(schema, 'querystring')) { | ||
warning.emit('FSTWRN001', 'querystring', method, url) | ||
FSTWRN001('querystring', method, url) | ||
} | ||
@@ -108,3 +108,3 @@ | ||
} else if (Object.prototype.hasOwnProperty.call(schema, 'params')) { | ||
warning.emit('FSTWRN001', 'params', method, url) | ||
FSTWRN001('params', method, url) | ||
} | ||
@@ -111,0 +111,0 @@ } |
'use strict' | ||
const warning = require('process-warning')() | ||
const { createDeprecation, createWarning } = require('process-warning') | ||
/** | ||
* Deprecation codes: | ||
* - FSTDEP005 | ||
*/ | ||
const FSTDEP005 = createDeprecation({ | ||
code: 'FSTDEP005', | ||
message: 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP005', 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.') | ||
const FSTDEP006 = createDeprecation({ | ||
code: 'FSTDEP006', | ||
message: 'You are decorating Request/Reply with a reference type. This reference is shared amongst all requests. Use onRequest hook instead. Property: %s' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP006', 'You are decorating Request/Reply with a reference type. This reference is shared amongst all requests. Use onRequest hook instead. Property: %s') | ||
const FSTDEP007 = createDeprecation({ | ||
code: 'FSTDEP007', | ||
message: 'You are trying to set a HEAD route using "exposeHeadRoute" route flag when a sibling route is already set. See documentation for more info.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP007', 'You are trying to set a HEAD route using "exposeHeadRoute" route flag when a sibling route is already set. See documentation for more info.') | ||
const FSTDEP008 = createDeprecation({ | ||
code: 'FSTDEP008', | ||
message: 'You are using route constraints via the route { version: "..." } option, use { constraints: { version: "..." } } option instead.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP008', 'You are using route constraints via the route { version: "..." } option, use { constraints: { version: "..." } } option instead.') | ||
const FSTDEP009 = createDeprecation({ | ||
code: 'FSTDEP009', | ||
message: 'You are using a custom route versioning strategy via the server { versioning: "..." } option, use { constraints: { version: "..." } } option instead.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP009', 'You are using a custom route versioning strategy via the server { versioning: "..." } option, use { constraints: { version: "..." } } option instead.') | ||
const FSTDEP010 = createDeprecation({ | ||
code: 'FSTDEP010', | ||
message: 'Modifying the "reply.sent" property is deprecated. Use the "reply.hijack()" method instead.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP010', 'Modifying the "reply.sent" property is deprecated. Use the "reply.hijack()" method instead.') | ||
const FSTDEP011 = createDeprecation({ | ||
code: 'FSTDEP011', | ||
message: 'Variadic listen method is deprecated. Please use ".listen(optionsObject)" instead. The variadic signature will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP011', 'Variadic listen method is deprecated. Please use ".listen(optionsObject)" instead. The variadic signature will be removed in `fastify@5`.') | ||
const FSTDEP012 = createDeprecation({ | ||
code: 'FSTDEP012', | ||
message: 'request.context property access is deprecated. Please use "request.routeOptions.config" or "request.routeOptions.schema" instead for accessing Route settings. The "request.context" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP012', 'request.context property access is deprecated. Please use "request.routeOptions.config" or "request.routeOptions.schema" instead for accessing Route settings. The "request.context" will be removed in `fastify@5`.') | ||
const FSTDEP013 = createDeprecation({ | ||
code: 'FSTDEP013', | ||
message: 'Direct return of "trailers" function is deprecated. Please use "callback" or "async-await" for return value. The support of direct return will removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP013', 'Direct return of "trailers" function is deprecated. Please use "callback" or "async-await" for return value. The support of direct return will removed in `fastify@5`.') | ||
const FSTDEP014 = createDeprecation({ | ||
code: 'FSTDEP014', | ||
message: 'You are trying to set/access the default route. This property is deprecated. Please, use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP014', 'You are trying to set/access the default route. This property is deprecated. Please, use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.') | ||
const FSTDEP015 = createDeprecation({ | ||
code: 'FSTDEP015', | ||
message: 'You are accessing the deprecated "request.routeSchema" property. Use "request.routeOptions.schema" instead. Property "req.routeSchema" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP015', 'You are accessing the deprecated "request.routeSchema" property. Use "request.routeOptions.schema" instead. Property "req.routeSchema" will be removed in `fastify@5`.') | ||
const FSTDEP016 = createDeprecation({ | ||
code: 'FSTDEP016', | ||
message: 'You are accessing the deprecated "request.routeConfig" property. Use "request.routeOptions.config" instead. Property "req.routeConfig" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP016', 'You are accessing the deprecated "request.routeConfig" property. Use "request.routeOptions.config" instead. Property "req.routeConfig" will be removed in `fastify@5`.') | ||
const FSTDEP017 = createDeprecation({ | ||
code: 'FSTDEP017', | ||
message: 'You are accessing the deprecated "request.routerPath" property. Use "request.routeOptions.url" instead. Property "req.routerPath" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP017', 'You are accessing the deprecated "request.routerPath" property. Use "request.routeOptions.url" instead. Property "req.routerPath" will be removed in `fastify@5`.') | ||
const FSTDEP018 = createDeprecation({ | ||
code: 'FSTDEP018', | ||
message: 'You are accessing the deprecated "request.routerMethod" property. Use "request.routeOptions.method" instead. Property "req.routerMethod" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP018', 'You are accessing the deprecated "request.routerMethod" property. Use "request.routeOptions.method" instead. Property "req.routerMethod" will be removed in `fastify@5`.') | ||
const FSTDEP019 = createDeprecation({ | ||
code: 'FSTDEP019', | ||
message: 'reply.context property access is deprecated. Please use "request.routeOptions.config" or "request.routeOptions.schema" instead for accessing Route settings. The "reply.context" will be removed in `fastify@5`.' | ||
}) | ||
warning.create('FastifyDeprecation', 'FSTDEP019', 'reply.context property access is deprecated. Please use "reply.routeOptions.config" or "reply.routeOptions.schema" instead for accessing Route settings. The "reply.context" will be removed in `fastify@5`.') | ||
const FSTWRN001 = createWarning({ | ||
name: 'FastifyWarning', | ||
code: 'FSTWRN001', | ||
message: 'The %s schema for %s: %s is missing. This may indicate the schema is not well specified.', | ||
unlimited: true | ||
}) | ||
warning.create('FastifyWarning', 'FSTWRN001', 'The %s schema for %s: %s is missing. This may indicate the schema is not well specified.', { unlimited: true }) | ||
const FSTWRN002 = createWarning({ | ||
name: 'FastifyWarning', | ||
code: 'FSTWRN002', | ||
message: 'The %s plugin being registered mixes async and callback styles, which will result in an error in `fastify@5`', | ||
unlimited: true | ||
}) | ||
module.exports = warning | ||
module.exports = { | ||
FSTDEP005, | ||
FSTDEP006, | ||
FSTDEP007, | ||
FSTDEP008, | ||
FSTDEP009, | ||
FSTDEP010, | ||
FSTDEP011, | ||
FSTDEP012, | ||
FSTDEP013, | ||
FSTDEP014, | ||
FSTDEP015, | ||
FSTDEP016, | ||
FSTDEP017, | ||
FSTDEP018, | ||
FSTDEP019, | ||
FSTWRN001, | ||
FSTWRN002 | ||
} |
{ | ||
"name": "fastify", | ||
"version": "4.24.3", | ||
"version": "4.25.2", | ||
"description": "Fast and low overhead web framework, for Node.js", | ||
@@ -28,3 +28,3 @@ "main": "fastify.js", | ||
"test:typescript": "tsc test/types/import.ts && tsd", | ||
"test:watch": "npm run unit -- -w --no-coverage-report -R terse", | ||
"test:watch": "npm run unit -- --watch --cov --no-coverage-report --reporter=terse", | ||
"unit": "c8 tap", | ||
@@ -201,4 +201,4 @@ "unit:junit": "tap-mocha-reporter xunit < out.tap > test/junit-testresults.xml", | ||
"light-my-request": "^5.11.0", | ||
"pino": "^8.16.0", | ||
"process-warning": "^2.2.0", | ||
"pino": "^8.17.0", | ||
"process-warning": "^3.0.0", | ||
"proxy-addr": "^2.0.7", | ||
@@ -205,0 +205,0 @@ "rfdc": "^1.3.0", |
@@ -1,2 +0,2 @@ | ||
<div align="center"> <a href="https://fastify.io/"> | ||
<div align="center"> <a href="https://fastify.dev/"> | ||
<img | ||
@@ -12,3 +12,3 @@ src="https://github.com/fastify/graphics/raw/HEAD/fastify-landscape-outlined.svg" | ||
[![CI](https://github.com/fastify/fastify/workflows/ci/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/ci.yml) | ||
[![CI](https://github.com/fastify/fastify/actions/workflows/ci.yml/badge.svg)](https://github.com/fastify/fastify/actions/workflows/ci.yml) | ||
[![Package Manager | ||
@@ -32,2 +32,3 @@ CI](https://github.com/fastify/fastify/workflows/package-manager-ci/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml) | ||
[![Discord](https://img.shields.io/discord/725613461949906985)](https://discord.gg/fastify) | ||
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod&color=blue)](https://gitpod.io/#https://github.com/fastify/fastify) | ||
@@ -289,2 +290,6 @@ </div> | ||
<https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor> | ||
* [__Manuel Spigolon__](https://github.com/eomm), | ||
<https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm> | ||
* [__James Sumners__](https://github.com/jsumners), | ||
<https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners> | ||
@@ -378,6 +383,6 @@ ### Fastify Core team | ||
src="https://github.com/openjs-foundation/artwork/blob/main/openjs_foundation/openjs_foundation-logo-horizontal-color.png?raw=true" | ||
width="250px;"/>](https://openjsf.org/projects/#growth) | ||
width="250px;"/>](https://openjsf.org/projects) | ||
We are a [Growth | ||
Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#growth-stage) | ||
We are a [At-Large | ||
Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#at-large-projects) | ||
in the [OpenJS Foundation](https://openjsf.org/). | ||
@@ -384,0 +389,0 @@ |
@@ -133,1 +133,28 @@ # Security Policy | ||
<https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners> | ||
## OpenSSF CII Best Practices | ||
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/7585/badge)](https://bestpractices.coreinfrastructure.org/projects/7585) | ||
There are three “tiers”: passing, silver, and gold. | ||
### Passing | ||
We meet 100% of the “passing” criteria. | ||
### Silver | ||
We meet 87% of the “silver” criteria. The gaps are as follows: | ||
- we do not have a DCO or a CLA process for contributions. | ||
- we do not currently document | ||
“what the user can and cannot expect in terms of security” for our project. | ||
- we do not currently document ”the architecture (aka high-level design)” | ||
for our project. | ||
### Gold | ||
We meet 70% of the “gold” criteria. The gaps are as follows: | ||
- we do not yet have the “silver” badge; see all the gaps above. | ||
- We do not include a copyright or license statement in each source file. | ||
Efforts are underway to change this archaic practice into a | ||
suggestion instead of a hard requirement. | ||
- There are a few unanswered questions around cryptography that are | ||
waiting for clarification. | ||
@@ -39,4 +39,4 @@ 'use strict' | ||
const isVgte19 = semver.gte(process.version, '19.0.0') | ||
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >= v19.x', { skip: isVgte19 }, async t => { | ||
const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0') | ||
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, async t => { | ||
const fastify = Fastify({ | ||
@@ -71,4 +71,4 @@ return503OnClosing: false, | ||
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip Node < v19.x', { skip: !isVgte19 }, async t => { | ||
// Since Node v19, we will always invoke server.closeIdleConnections() | ||
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, async t => { | ||
// Since Node v18, we will always invoke server.closeIdleConnections() | ||
// therefore our socket will be closed | ||
@@ -75,0 +75,0 @@ const fastify = Fastify({ |
@@ -207,4 +207,4 @@ 'use strict' | ||
const isV19plus = semver.gte(process.version, '19.0.0') | ||
test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >= v19.x', { skip: isV19plus }, t => { | ||
const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0') | ||
test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, t => { | ||
const fastify = Fastify({ | ||
@@ -247,3 +247,3 @@ return503OnClosing: false, | ||
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node < v19.x', { skip: !isV19plus }, t => { | ||
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, t => { | ||
t.plan(4) | ||
@@ -250,0 +250,0 @@ const fastify = Fastify({ |
@@ -14,3 +14,3 @@ 'use strict' | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -25,3 +25,3 @@ reply.send({ hello: 'world' }) | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
@@ -61,5 +61,5 @@ }, (err, res) => { | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
reply.send('fastify.io') | ||
reply.send('fastify.dev') | ||
} | ||
@@ -81,3 +81,3 @@ }) | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
@@ -87,3 +87,3 @@ }, (err, res) => { | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.payload, 'fastify.io') | ||
t.equal(res.payload, 'fastify.dev') | ||
}) | ||
@@ -487,3 +487,3 @@ | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -542,5 +542,5 @@ reply.send({ hello: 'from any other domain' }) | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
reply.send({ hello: 'from fastify.io' }) | ||
reply.send({ hello: 'from fastify.dev' }) | ||
} | ||
@@ -561,7 +561,7 @@ }) | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.same(JSON.parse(res.payload), { hello: 'from fastify.io' }) | ||
t.same(JSON.parse(res.payload), { hello: 'from fastify.dev' }) | ||
t.equal(res.statusCode, 200) | ||
@@ -591,3 +591,3 @@ }) | ||
method: 'GET', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
path: '/route', | ||
@@ -604,3 +604,3 @@ handler: (req, reply) => { | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
@@ -621,3 +621,3 @@ }, (err, res) => { | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -632,3 +632,3 @@ reply.header('content-type', 'text/plain') | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -643,3 +643,3 @@ reply.send({ hello: 'from any other domain' }) | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
@@ -669,3 +669,3 @@ }, (err, res) => { | ||
url: '/', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -681,3 +681,3 @@ reply.header('content-type', 'text/plain') | ||
headers: { | ||
host: 'fastify.io' | ||
host: 'fastify.dev' | ||
} | ||
@@ -700,3 +700,3 @@ }, (err, res) => { | ||
path: '/route', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -710,3 +710,3 @@ reply.header('content-type', 'text/plain') | ||
path: '/route', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -743,3 +743,3 @@ reply.send({ ok: true }) | ||
path: '/route', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -754,3 +754,3 @@ reply.header('content-type', 'text/plain') | ||
path: '/route', | ||
constraints: { host: 'fastify.io' }, | ||
constraints: { host: 'fastify.dev' }, | ||
handler: (req, reply) => { | ||
@@ -891,3 +891,3 @@ reply.send({ ok: true }) | ||
url: '/', | ||
constraints: { host: /.*\.fastify\.io/ }, | ||
constraints: { host: /.*\.fastify\.dev$/ }, | ||
handler: (req, reply) => { | ||
@@ -902,3 +902,3 @@ reply.send({ hello: 'from fastify dev domain' }) | ||
headers: { | ||
host: 'dev.fastify.io' | ||
host: 'dev.fastify.dev' | ||
} | ||
@@ -905,0 +905,0 @@ }, (err, res) => { |
@@ -793,12 +793,13 @@ 'use strict' | ||
test('decorate* should emit warning if an array is passed', t => { | ||
t.plan(2) | ||
function onWarning (code, name) { | ||
t.plan(1) | ||
function onWarning (name) { | ||
t.equal(name, 'test_array') | ||
t.equal(code, 'FSTDEP006') | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const decorate = proxyquire('../lib/decorate', { './warnings': warning }) | ||
const decorate = proxyquire('../lib/decorate', { | ||
'./warnings': { | ||
FSTDEP006: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/decorate.js': decorate })() | ||
@@ -809,12 +810,13 @@ fastify.decorateRequest('test_array', []) | ||
test('decorate* should emit warning if object type is passed', t => { | ||
t.plan(2) | ||
function onWarning (code, name) { | ||
t.plan(1) | ||
function onWarning (name) { | ||
t.equal(name, 'test_object') | ||
t.equal(code, 'FSTDEP006') | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const decorate = proxyquire('../lib/decorate', { './warnings': warning }) | ||
const decorate = proxyquire('../lib/decorate', { | ||
'./warnings': { | ||
FSTDEP006: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/decorate.js': decorate })() | ||
@@ -828,6 +830,8 @@ fastify.decorateRequest('test_object', { foo: 'bar' }) | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const decorate = proxyquire('../lib/decorate', { './warnings': warning }) | ||
const decorate = proxyquire('../lib/decorate', { | ||
'./warnings': { | ||
FSTDEP006: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/decorate.js': decorate })() | ||
@@ -850,7 +854,8 @@ | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const decorate = proxyquire('../lib/decorate', { './warnings': warning }) | ||
const decorate = proxyquire('../lib/decorate', { | ||
'./warnings': { | ||
FSTDEP006: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/decorate.js': decorate })() | ||
@@ -857,0 +862,0 @@ |
@@ -6,3 +6,3 @@ 'use strict' | ||
const Fastify = require('..') | ||
const warning = require('../lib/warnings') | ||
const { FSTDEP014 } = require('../lib/warnings') | ||
@@ -22,4 +22,4 @@ // Silence the standard warning logs. We will test the messages explicitly. | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'FSTDEP014') | ||
t.equal(warning.name, 'DeprecationWarning') | ||
t.equal(warning.code, FSTDEP014.code) | ||
} | ||
@@ -29,3 +29,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTDEP014', false) | ||
FSTDEP014.emitted = false | ||
}) | ||
@@ -43,4 +43,4 @@ | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'FSTDEP014') | ||
t.equal(warning.name, 'DeprecationWarning') | ||
t.equal(warning.code, FSTDEP014.code) | ||
} | ||
@@ -50,3 +50,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTDEP014', false) | ||
FSTDEP014.emitted = false | ||
}) | ||
@@ -53,0 +53,0 @@ |
@@ -135,2 +135,122 @@ 'use strict' | ||
test('ready should resolve in order when called multiply times (promises only)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5] | ||
const result = [] | ||
const promises = [1, 2, 3, 4, 5] | ||
.map((id) => app.ready().then(() => result.push(id))) | ||
await Promise.all(promises) | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should reject in order when called multiply times (promises only)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5] | ||
const result = [] | ||
app.register((instance, opts, done) => { | ||
setTimeout(() => done(new Error('test')), 500) | ||
}) | ||
const promises = [1, 2, 3, 4, 5] | ||
.map((id) => app.ready().catch(() => result.push(id))) | ||
await Promise.all(promises) | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should reject in order when called multiply times (callbacks only)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5] | ||
const result = [] | ||
app.register((instance, opts, done) => { | ||
setTimeout(() => done(new Error('test')), 500) | ||
}) | ||
expectedOrder.map((id) => app.ready(() => result.push(id))) | ||
await app.ready().catch(err => { | ||
t.equal(err.message, 'test') | ||
}) | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should resolve in order when called multiply times (callbacks only)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5] | ||
const result = [] | ||
expectedOrder.map((id) => app.ready(() => result.push(id))) | ||
await app.ready() | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should resolve in order when called multiply times (mixed)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5, 6] | ||
const result = [] | ||
for (const order of expectedOrder) { | ||
if (order % 2) { | ||
app.ready(() => result.push(order)) | ||
} else { | ||
app.ready().then(() => result.push(order)) | ||
} | ||
} | ||
await app.ready() | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should reject in order when called multiply times (mixed)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5, 6] | ||
const result = [] | ||
app.register((instance, opts, done) => { | ||
setTimeout(() => done(new Error('test')), 500) | ||
}) | ||
for (const order of expectedOrder) { | ||
if (order % 2) { | ||
app.ready(() => result.push(order)) | ||
} else { | ||
app.ready().then(null, () => result.push(order)) | ||
} | ||
} | ||
await app.ready().catch(err => { | ||
t.equal(err.message, 'test') | ||
}) | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('ready should resolve in order when called multiply times (mixed)', async (t) => { | ||
const app = Fastify() | ||
const expectedOrder = [1, 2, 3, 4, 5, 6] | ||
const result = [] | ||
for (const order of expectedOrder) { | ||
if (order % 2) { | ||
app.ready().then(() => result.push(order)) | ||
} else { | ||
app.ready(() => result.push(order)) | ||
} | ||
} | ||
await app.ready() | ||
t.strictSame(result, expectedOrder, 'Should resolve in order') | ||
}) | ||
test('fastify instance should contains listeningOrigin property (with port and host)', async t => { | ||
@@ -137,0 +257,0 @@ t.plan(1) |
@@ -38,2 +38,18 @@ 'use strict' | ||
t.test('onReady should be called once', async (t) => { | ||
const app = Fastify() | ||
let counter = 0 | ||
app.addHook('onReady', async function () { | ||
counter++ | ||
}) | ||
const promises = [1, 2, 3, 4, 5].map((id) => app.ready().then(() => id)) | ||
const result = await Promise.race(promises) | ||
t.strictSame(result, 1, 'Should resolve in order') | ||
t.equal(counter, 1, 'Should call onReady only once') | ||
}) | ||
t.test('async onReady should be called in order', async t => { | ||
@@ -40,0 +56,0 @@ t.plan(7) |
@@ -31,3 +31,3 @@ 'use strict' | ||
const constrain = 'fastify.io' | ||
const constrain = 'fastify.dev' | ||
@@ -34,0 +34,0 @@ fastify.route({ |
@@ -295,3 +295,3 @@ 'use strict' | ||
t.equal(error.code, 'FST_ERR_MISSING_MIDDLEWARE') | ||
t.equal(error.message, 'You must register a plugin for handling middlewares, visit fastify.io/docs/latest/Reference/Middleware/ for more info.') | ||
t.equal(error.message, 'You must register a plugin for handling middlewares, visit fastify.dev/docs/latest/Reference/Middleware/ for more info.') | ||
t.equal(error.statusCode, 500) | ||
@@ -821,2 +821,27 @@ t.ok(error instanceof Error) | ||
test('Ensure that all errors are in Errors.md TOC', t => { | ||
t.plan(78) | ||
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8') | ||
const exportedKeys = Object.keys(errors) | ||
for (const key of exportedKeys) { | ||
if (errors[key].name === 'FastifyError') { | ||
t.ok(errorsMd.includes(` - [${key.toUpperCase()}](#${key.toLowerCase()})`), key) | ||
} | ||
} | ||
}) | ||
test('Ensure that non-existing errors are not in Errors.md TOC', t => { | ||
t.plan(78) | ||
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8') | ||
const matchRE = / {4}- \[([A-Z0-9_]+)\]\(#[a-z0-9_]+\)/g | ||
const matches = errorsMd.matchAll(matchRE) | ||
const exportedKeys = Object.keys(errors) | ||
for (const match of matches) { | ||
t.ok(exportedKeys.indexOf(match[1]) !== -1, match[1]) | ||
} | ||
}) | ||
test('Ensure that all errors are in Errors.md documented', t => { | ||
@@ -829,3 +854,3 @@ t.plan(78) | ||
if (errors[key].name === 'FastifyError') { | ||
t.ok(errorsMd.includes(`#### ${key}\n`), key) | ||
t.ok(errorsMd.includes(`<a id="${key.toLowerCase()}">${key.toUpperCase()}</a>`), key) | ||
} | ||
@@ -839,3 +864,3 @@ } | ||
const matchRE = /#### ([0-9a-zA-Z_]+)\n/g | ||
const matchRE = /<a id="[0-9a-zA-Z_]+">([0-9a-zA-Z_]+)<\/a>/g | ||
const matches = errorsMd.matchAll(matchRE) | ||
@@ -842,0 +867,0 @@ const exportedKeys = Object.keys(errors) |
@@ -22,3 +22,3 @@ 'use strict' | ||
const path = require('node:path') | ||
const warning = require('../../lib/warnings') | ||
const { FSTDEP019, FSTDEP010 } = require('../../lib/warnings') | ||
@@ -1470,4 +1470,3 @@ const agent = new http.Agent({ keepAlive: false }) | ||
const deprecationCode = 'FSTDEP010' | ||
warning.emitted.delete(deprecationCode) | ||
FSTDEP010.emitted = false | ||
@@ -1477,4 +1476,4 @@ process.removeAllListeners('warning') | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, deprecationCode) | ||
t.equal(warning.name, 'DeprecationWarning') | ||
t.equal(warning.code, FSTDEP010.code) | ||
} | ||
@@ -1500,4 +1499,3 @@ | ||
const deprecationCode = 'FSTDEP019' | ||
warning.emitted.delete(deprecationCode) | ||
FSTDEP019.emitted = false | ||
@@ -1507,4 +1505,4 @@ process.removeAllListeners('warning') | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, deprecationCode) | ||
t.equal(warning.name, 'DeprecationWarning') | ||
t.equal(warning.code, FSTDEP019.code) | ||
} | ||
@@ -2156,1 +2154,27 @@ | ||
}) | ||
test('Uint8Array view of ArrayBuffer returns correct byteLength', t => { | ||
t.plan(5) | ||
const fastify = Fastify() | ||
const arrBuf = new ArrayBuffer(100) | ||
const arrView = new Uint8Array(arrBuf, 0, 10) | ||
fastify.get('/', function (req, reply) { | ||
return reply.send(arrView) | ||
}) | ||
fastify.listen({ port: 0 }, err => { | ||
t.error(err) | ||
t.teardown(fastify.close.bind(fastify)) | ||
fastify.inject({ | ||
method: 'GET', | ||
url: '/' | ||
}, (err, response) => { | ||
t.error(err) | ||
t.equal(response.headers['content-type'], 'application/octet-stream') | ||
t.equal(response.headers['content-length'], '10') | ||
t.same(response.rawPayload.byteLength, arrView.byteLength) | ||
}) | ||
}) | ||
}) |
@@ -154,3 +154,4 @@ 'use strict' | ||
const { file, cleanup } = createTempFile(t) | ||
if (process.env.CITGM) { fs.writeFileSync(file, '') } | ||
// 0600 permissions (read/write for owner only) | ||
if (process.env.CITGM) { fs.writeFileSync(file, '', { mode: 0o600 }) } | ||
@@ -157,0 +158,0 @@ const fastify = Fastify({ |
@@ -417,1 +417,48 @@ 'use strict' | ||
}) | ||
test('registering plugins with mixed style should return a warning', async t => { | ||
t.plan(12) | ||
const pluginNames = ['error-plugin', 'anonymous', 'anotherPlugin', 'anotherPluginNamed'] | ||
const oldWarnings = process.listeners('warning') | ||
process.removeAllListeners('warning') | ||
process.on('warning', onWarning) | ||
function onWarning (warning) { | ||
t.match(warning.message, new RegExp(`.*${pluginNames.shift()} plugin being registered mixes async and callback styles.*`)) | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN002') | ||
} | ||
t.teardown(() => { | ||
process.removeListener('warning', onWarning) | ||
for (const warning of oldWarnings) { | ||
process.on('warning', warning) | ||
} | ||
}) | ||
const fastify = Fastify() | ||
const pluginName = 'error-plugin' | ||
const errorPlugin = async (app, opts, done) => { | ||
done() | ||
} | ||
const namedPlugin = fp(errorPlugin, { name: pluginName }) | ||
async function anotherPlugin (app, opts, done) { | ||
done() | ||
} | ||
const anotherPluginNamed = async function (app, opts, done) { | ||
done() | ||
} | ||
fastify.register(namedPlugin) | ||
fastify.register(async (app, opts, done) => { | ||
done() | ||
}) | ||
fastify.register(anotherPlugin) | ||
fastify.register(anotherPluginNamed) | ||
await fastify.ready() | ||
}) |
@@ -108,3 +108,3 @@ 'use strict' | ||
await fastify.register(async (instance, opts, done) => { | ||
await fastify.register(async (instance, opts) => { | ||
first = true | ||
@@ -115,3 +115,3 @@ }) | ||
fastify.register(async (instance, opts, done) => { | ||
fastify.register(async (instance, opts) => { | ||
second = true | ||
@@ -123,3 +123,3 @@ }) | ||
fastify.register(async (instance, opts, done) => { | ||
fastify.register(async (instance, opts) => { | ||
third = true | ||
@@ -151,3 +151,3 @@ }) | ||
fastify.register(async (instance, opts, done) => { | ||
fastify.register(async (instance, opts) => { | ||
t.fail('should not be executed') | ||
@@ -174,3 +174,3 @@ }) | ||
fastify.register(async (instance, opts, done) => { | ||
fastify.register(async (instance, opts) => { | ||
t.fail('should not be executed') | ||
@@ -177,0 +177,0 @@ }) |
'use strict' | ||
const t = require('tap') | ||
const { Readable } = require('stream') | ||
const test = t.test | ||
@@ -62,3 +63,3 @@ const Fastify = require('..') | ||
test('code should handle 204', t => { | ||
t.plan(8) | ||
t.plan(13) | ||
@@ -76,2 +77,14 @@ const fastify = Fastify() | ||
fastify.get('/stream/204', function (request, reply) { | ||
const stream = new Readable({ | ||
read () { | ||
this.push(null) | ||
} | ||
}) | ||
stream.on('end', () => { | ||
t.pass('stream ended') | ||
}) | ||
reply.status(204).send(stream) | ||
}) | ||
fastify.inject({ | ||
@@ -96,2 +109,12 @@ method: 'GET', | ||
}) | ||
fastify.inject({ | ||
method: 'GET', | ||
url: '/stream/204' | ||
}, (error, res) => { | ||
t.error(error) | ||
t.equal(res.statusCode, 204) | ||
t.equal(res.payload, '') | ||
t.equal(res.headers['content-length'], undefined) | ||
}) | ||
}) | ||
@@ -98,0 +121,0 @@ |
@@ -203,3 +203,3 @@ 'use strict' | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.name, 'DeprecationWarning') | ||
t.equal(warning.code, 'FSTDEP013') | ||
@@ -206,0 +206,0 @@ } |
@@ -181,10 +181,11 @@ 'use strict' | ||
function onWarning (code) { | ||
t.equal(code, 'FSTDEP007') | ||
function onWarning () { | ||
t.pass('warning emitted') | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const route = proxyquire('../lib/route', { './warnings': warning }) | ||
const route = proxyquire('../lib/route', { | ||
'./warnings': { | ||
FSTDEP007: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/route.js': route })() | ||
@@ -191,0 +192,0 @@ |
@@ -543,3 +543,3 @@ 'use strict' | ||
id: '254381a5-888c-4b41-8116-e3b1a54980bd', | ||
email: 'info@fastify.io' | ||
email: 'info@fastify.dev' | ||
}, | ||
@@ -556,3 +556,3 @@ url: '/' | ||
id: 'invalid', | ||
email: 'info@fastify.io' | ||
email: 'info@fastify.dev' | ||
}, | ||
@@ -559,0 +559,0 @@ url: '/' |
@@ -9,3 +9,3 @@ 'use strict' | ||
const { kSchemaController } = require('../lib/symbols.js') | ||
const warning = require('../lib/warnings') | ||
const { FSTWRN001 } = require('../lib/warnings') | ||
@@ -265,3 +265,3 @@ const echoParams = (req, reply) => { reply.send(req.params) } | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN001') | ||
t.equal(warning.code, FSTWRN001.code) | ||
} | ||
@@ -271,3 +271,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTWRN001', false) | ||
FSTWRN001.emitted = false | ||
}) | ||
@@ -298,3 +298,3 @@ | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN001') | ||
t.equal(warning.code, FSTWRN001.code) | ||
} | ||
@@ -304,3 +304,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTWRN001', false) | ||
FSTWRN001.emitted = false | ||
}) | ||
@@ -331,3 +331,3 @@ | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN001') | ||
t.equal(warning.code, FSTWRN001.code) | ||
} | ||
@@ -337,3 +337,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTWRN001', false) | ||
FSTWRN001.emitted = false | ||
}) | ||
@@ -364,3 +364,3 @@ | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN001') | ||
t.equal(warning.code, FSTWRN001.code) | ||
} | ||
@@ -370,3 +370,3 @@ | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTWRN001', false) | ||
FSTWRN001.emitted = false | ||
}) | ||
@@ -402,3 +402,3 @@ | ||
t.equal(warning.name, 'FastifyWarning') | ||
t.equal(warning.code, 'FSTWRN001') | ||
t.equal(warning.code, FSTWRN001.code) | ||
t.equal(runs++, expectedWarningEmitted.shift()) | ||
@@ -410,3 +410,3 @@ } | ||
process.removeListener('warning', onWarning) | ||
warning.emitted.set('FSTWRN001', false) | ||
FSTWRN001.emitted = false | ||
}) | ||
@@ -413,0 +413,0 @@ |
@@ -7,2 +7,3 @@ 'use strict' | ||
const semver = require('semver') | ||
const undici = require('undici') | ||
@@ -127,1 +128,51 @@ test('listen should accept null port', t => { | ||
}) | ||
t.test('#5180 - preClose should be called before closing secondary server', t => { | ||
t.plan(2) | ||
const fastify = Fastify({ forceCloseConnections: true }) | ||
let flag = false | ||
t.teardown(fastify.close.bind(fastify)) | ||
fastify.addHook('preClose', async () => { | ||
flag = true | ||
}) | ||
fastify.get('/', async (req, reply) => { | ||
await new Promise((resolve) => { | ||
setTimeout(() => resolve(1), 1000) | ||
}) | ||
return { hello: 'world' } | ||
}) | ||
fastify.listen({ port: 0 }, (err) => { | ||
t.error(err) | ||
const addresses = fastify.addresses() | ||
const mainServerAddress = fastify.server.address() | ||
let secondaryAddress | ||
for (const addr of addresses) { | ||
if (addr.family !== mainServerAddress.family) { | ||
secondaryAddress = addr | ||
secondaryAddress.address = secondaryAddress.family === 'IPv6' | ||
? `[${secondaryAddress.address}]` | ||
: secondaryAddress.address | ||
break | ||
} | ||
} | ||
if (!secondaryAddress) { | ||
t.pass('no secondary server') | ||
return | ||
} | ||
undici.request(`http://${secondaryAddress.address}:${secondaryAddress.port}/`) | ||
.then( | ||
() => { t.fail('Request should not succeed') }, | ||
() => { t.ok(flag) } | ||
) | ||
setTimeout(() => { | ||
fastify.close() | ||
}, 250) | ||
}) | ||
}) |
@@ -17,3 +17,3 @@ import { FastifyError } from '@fastify/error' | ||
} from '../../fastify' | ||
import { RequestPayload, preHandlerAsyncHookHandler } from '../../types/hooks' | ||
import { DoneFuncWithErrOrRes, HookHandlerDoneFunction, RequestPayload, preHandlerAsyncHookHandler } from '../../types/hooks' | ||
import { FastifyRouteConfig, RouteGenericInterface } from '../../types/route' | ||
@@ -396,2 +396,125 @@ | ||
server.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
onRequest: (request, reply, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
onRequestAbort: (request, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
preParsing: (request, reply, payload, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<RequestPayload>(payload) | ||
expectType<<TError extends Error = FastifyError>(err?: TError | null | undefined, res?: RequestPayload | undefined) => void>(done) | ||
}, | ||
preValidation: (request, reply, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
preHandler: (request, reply, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
preSerialization: (request, reply, payload, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<unknown>(payload) | ||
expectType<DoneFuncWithErrOrRes>(done) | ||
}, | ||
onSend: (request, reply, payload, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<unknown>(payload) | ||
expectType<DoneFuncWithErrOrRes>(done) | ||
}, | ||
onResponse: (request, reply, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
onTimeout: (request, reply, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<HookHandlerDoneFunction>(done) | ||
}, | ||
onError: (request, reply, error, done) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<FastifyError>(error) | ||
expectType<() => void>(done) | ||
} | ||
}) | ||
server.get('/', { | ||
onRequest: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
onRequestAbort: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
}, | ||
preParsing: async (request, reply, payload) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<RequestPayload>(payload) | ||
}, | ||
preValidation: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
preHandler: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
preSerialization: async (request, reply, payload) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<unknown>(payload) | ||
}, | ||
onSend: async (request, reply, payload) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<unknown>(payload) | ||
}, | ||
onResponse: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
onTimeout: async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}, | ||
onError: async (request, reply, error) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
expectType<FastifyError>(error) | ||
} | ||
}, async (request, reply) => { | ||
expectType<FastifyRequest>(request) | ||
expectType<FastifyReply>(reply) | ||
}) | ||
// TODO: Should throw errors | ||
// expectError(server.get('/', { onRequest: async (request, reply, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { onRequestAbort: async (request, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { preParsing: async (request, reply, payload, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { preValidation: async (request, reply, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { preHandler: async (request, reply, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { preSerialization: async (request, reply, payload, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { onSend: async (request, reply, payload, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { onResponse: async (request, reply, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { onTimeout: async (request, reply, done) => {} }, async (request, reply) => {})) | ||
// expectError(server.get('/', { onError: async (request, reply, error, done) => {} }, async (request, reply) => {})) | ||
server.addHook('preClose', function (done) { | ||
@@ -398,0 +521,0 @@ expectType<FastifyInstance>(this) |
@@ -259,2 +259,14 @@ import { expectAssignable, expectDeprecated, expectError, expectNotDeprecated, expectType } from 'tsd' | ||
// test after method | ||
expectAssignable<FastifyInstance>(server.after()) | ||
expectAssignable<FastifyInstance>(server.after((err) => { | ||
expectType<Error | null>(err) | ||
})) | ||
// test ready method | ||
expectAssignable<FastifyInstance>(server.ready()) | ||
expectAssignable<FastifyInstance>(server.ready((err) => { | ||
expectType<Error | null>(err) | ||
})) | ||
expectAssignable<void>(server.routing({} as RawRequestDefaultExpression, {} as RawReplyDefaultExpression)) | ||
@@ -261,0 +273,0 @@ |
@@ -77,2 +77,16 @@ import { expectAssignable, expectDeprecated, expectError, expectNotAssignable, expectType } from 'tsd' | ||
serverWithPino.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler (request) { | ||
expectType<P.Logger>(this.log) | ||
expectType<P.Logger>(request.log) | ||
} | ||
}) | ||
serverWithPino.get('/', function (request) { | ||
expectType<P.Logger>(this.log) | ||
expectType<P.Logger>(request.log) | ||
}) | ||
const serverWithLogOptions = fastify< | ||
@@ -79,0 +93,0 @@ Server, |
@@ -25,8 +25,8 @@ import { Buffer } from 'buffer' | ||
expectType<((payload?: unknown) => FastifyReply)>(reply.send) | ||
expectType<(key: string, value: any) => FastifyReply>(reply.header) | ||
expectType<(values: {[key: string]: any}) => FastifyReply>(reply.headers) | ||
expectType<(key: string) => number | string | string[] | undefined>(reply.getHeader) | ||
expectType<() => { [key: string]: number | string | string[] | undefined }>(reply.getHeaders) | ||
expectType<(key: string) => FastifyReply>(reply.removeHeader) | ||
expectType<(key: string) => boolean>(reply.hasHeader) | ||
expectAssignable<(key: string, value: any) => FastifyReply>(reply.header) | ||
expectAssignable<(values: {[key: string]: any}) => FastifyReply>(reply.headers) | ||
expectAssignable<(key: string) => number | string | string[] | undefined>(reply.getHeader) | ||
expectAssignable<() => { [key: string]: number | string | string[] | undefined }>(reply.getHeaders) | ||
expectAssignable<(key: string) => FastifyReply>(reply.removeHeader) | ||
expectAssignable<(key: string) => boolean>(reply.hasHeader) | ||
expectType<{(statusCode: number, url: string): FastifyReply; (url: string): FastifyReply }>(reply.redirect) | ||
@@ -166,1 +166,20 @@ expectType<() => FastifyReply>(reply.hijack) | ||
}) | ||
const httpHeaderHandler: RouteHandlerMethod = function (_request, reply) { | ||
// accept is a header provided by @types/node | ||
reply.getHeader('accept') | ||
reply.getHeaders().accept // eslint-disable-line no-unused-expressions | ||
reply.hasHeader('accept') | ||
reply.header('accept', 'test') | ||
reply.headers({ accept: 'test' }) | ||
reply.removeHeader('accept') | ||
// x-fastify-test is not a header provided by @types/node | ||
// and should not result in a typing error | ||
reply.getHeader('x-fastify-test') | ||
reply.getHeaders()['x-fastify-test'] // eslint-disable-line no-unused-expressions | ||
reply.hasHeader('x-fastify-test') | ||
reply.header('x-fastify-test', 'test') | ||
reply.headers({ 'x-fastify-test': 'test' }) | ||
reply.removeHeader('x-fastify-test') | ||
} |
@@ -85,2 +85,3 @@ import pino from 'pino' | ||
expectType<FastifySchema>(request.routeOptions.schema) | ||
expectType<RouteHandlerMethod>(request.routeOptions.handler) | ||
@@ -125,3 +126,3 @@ expectType<RequestHeadersDefault & RawRequestDefaultExpression['headers']>(request.headers) | ||
expectType<RequestQuerystring>(request.query) | ||
if (typeof request.body === 'undefined') { | ||
if (request.body === undefined) { | ||
expectType<undefined>(request.body) | ||
@@ -154,3 +155,3 @@ } else { | ||
foo: () => { }, // custom severity logger method | ||
child: () => customLogger as pino.Logger<never> | ||
child: () => customLogger | ||
} | ||
@@ -157,0 +158,0 @@ |
@@ -425,2 +425,33 @@ import { FastifyError } from '@fastify/error' | ||
expectType<boolean>(fastify().hasRoute({ | ||
url: '/', | ||
method: 'GET', | ||
constraints: { host: 'auth.fastify.dev' } | ||
})) | ||
expectType<boolean>(fastify().hasRoute({ | ||
url: '/', | ||
method: 'GET', | ||
constraints: { host: /.*\.fastify\.dev$/ } | ||
})) | ||
expectType<boolean>(fastify().hasRoute({ | ||
url: '/', | ||
method: 'GET', | ||
constraints: { host: /.*\.fastify\.dev$/, version: '1.2.3' } | ||
})) | ||
expectType<boolean>(fastify().hasRoute({ | ||
url: '/', | ||
method: 'GET', | ||
constraints: { | ||
// constraints value should accept any value | ||
number: 12, | ||
date: new Date(), | ||
boolean: true, | ||
function: () => {}, | ||
object: { foo: 'bar' } | ||
} | ||
})) | ||
expectType<FastifyInstance>(fastify().route({ | ||
@@ -427,0 +458,0 @@ url: '/', |
@@ -666,10 +666,11 @@ 'use strict' | ||
function onWarning (code) { | ||
t.equal(code, 'FSTDEP008') | ||
function onWarning () { | ||
t.pass('FSTDEP008 has been emitted') | ||
} | ||
const warning = { | ||
emit: onWarning | ||
} | ||
const route = proxyquire('../lib/route', { './warnings': warning }) | ||
const route = proxyquire('../lib/route', { | ||
'./warnings': { | ||
FSTDEP008: onWarning | ||
} | ||
}) | ||
const fastify = proxyquire('..', { './lib/route.js': route })({ exposeHeadRoutes: false }) | ||
@@ -676,0 +677,0 @@ |
@@ -64,2 +64,20 @@ import { Readable } from 'stream' | ||
// helper type which infers whether onRequestHookHandler or onRequestAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type onRequestMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -106,2 +124,20 @@ * `preParsing` is the second hook to be executed in the request lifecycle. The previous hook was `onRequest`, the next hook will be `preValidation`. | ||
// helper type which infers whether preParsingHookHandler or preParsingAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type preParsingMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -145,2 +181,20 @@ * `preValidation` is the third hook to be executed in the request lifecycle. The previous hook was `preParsing`, the next hook will be `preHandler`. | ||
// helper type which infers whether preValidationHookHandler or preValidationAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type preValidationMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -184,2 +238,20 @@ * `preHandler` is the fourth hook to be executed in the request lifecycle. The previous hook was `preValidation`, the next hook will be `preSerialization`. | ||
// helper type which infers whether preHandlerHookHandler or preHandlerAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type preHandlerMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
// This is used within the `preSerialization` and `onSend` hook handlers | ||
@@ -235,2 +307,21 @@ interface DoneFuncWithErrOrRes { | ||
// helper type which infers whether preSerializationHookHandler or preSerializationAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type preSerializationMetaHookHandler< | ||
PreSerializationPayload = unknown, | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -279,2 +370,21 @@ * You can change the payload with the `onSend` hook. It is the sixth hook to be executed in the request lifecycle. The previous hook was `preSerialization`, the next hook will be `onResponse`. | ||
// helper type which infers whether onSendHookHandler or onSendAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type onSendMetaHookHandler< | ||
OnSendPayload = unknown, | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -319,2 +429,20 @@ * `onResponse` is the seventh and last hook in the request hook lifecycle. The previous hook was `onSend`, there is no next hook. | ||
// helper type which infers whether onResponseHookHandler or onResponseAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type onResponseMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -359,2 +487,20 @@ * `onTimeout` is useful if you need to monitor the request timed out in your service. (if the `connectionTimeout` property is set on the fastify instance) | ||
// helper type which infers whether onTimeoutHookHandler or onTimeoutAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type onTimeoutMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -405,2 +551,21 @@ * This hook is useful if you need to do some custom error logging or add some specific header in case of error. | ||
// helper type which infers whether onErrorHookHandler or onErrorAsyncHookHandler are | ||
// applicable based on the specified return type. | ||
export type onErrorMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
TError extends Error = FastifyError, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger>> | ||
? onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger> | ||
: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, TError, SchemaCompiler, TypeProvider, Logger> | ||
/** | ||
@@ -444,2 +609,20 @@ * `onRequestAbort` is useful if you need to monitor the if the client aborts the request (if the `request.raw.aborted` property is set to `true`). | ||
// helper type which infers whether onRequestAbortHookHandler or onRequestAbortHookHandler are | ||
// applicable based on the specified return type. | ||
export type onRequestAbortMetaHookHandler< | ||
RawServer extends RawServerBase = RawServerDefault, | ||
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>, | ||
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>, | ||
RouteGeneric extends RouteGenericInterface = RouteGenericInterface, | ||
ContextConfig = ContextConfigDefault, | ||
SchemaCompiler extends FastifySchema = FastifySchema, | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger, | ||
Return extends ReturnType<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
| ReturnType<onRequestAbortAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
= ReturnType<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
> = Return extends ReturnType<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>> | ||
? onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
: onRequestAbortAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
export type LifecycleHook = 'onRequest' | ||
@@ -446,0 +629,0 @@ | 'preParsing' |
@@ -140,3 +140,3 @@ import { FastifyError } from '@fastify/error' | ||
after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>; | ||
after(afterListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
after(afterListener: (err: Error | null) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
@@ -194,3 +194,3 @@ close(): Promise<undefined>; | ||
ready(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>; | ||
ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
ready(readyListener: (err: Error | null) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
@@ -207,12 +207,12 @@ register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>>; | ||
const SchemaCompiler extends FastifySchema = FastifySchema, | ||
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>; | ||
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>; | ||
@@ -219,0 +219,0 @@ hasRoute< |
@@ -9,3 +9,3 @@ import { Buffer } from 'buffer' | ||
import { FastifyReplyType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyReplyType } from './type-provider' | ||
import { CodeToReplyKey, ContextConfigDefault, HttpKeys, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, ReplyDefault, ReplyKeysToCodes } from './utils' | ||
import { CodeToReplyKey, ContextConfigDefault, HttpKeys, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, ReplyDefault, ReplyKeysToCodes, HttpHeader } from './utils' | ||
@@ -52,11 +52,8 @@ export interface ReplyGenericInterface { | ||
send(payload?: ReplyType): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
header(key: string, value: any): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
headers(values: {[key: string]: any}): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
getHeader(key: string): number | string | string[] | undefined; | ||
getHeaders(): { | ||
// Node's `getHeaders()` can return numbers and arrays, so they're included here as possible types. | ||
[key: string]: number | string | string[] | undefined; | ||
}; | ||
removeHeader(key: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
hasHeader(key: string): boolean; | ||
header(key: HttpHeader, value: any): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
headers(values: Partial<Record<HttpHeader, number | string | string[] | undefined>>): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
getHeader(key: HttpHeader): number | string | string[] | undefined; | ||
getHeaders(): Record<HttpHeader, number | string | string[] | undefined>; | ||
removeHeader(key: HttpHeader): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
hasHeader(key: HttpHeader): boolean; | ||
// Note: should consider refactoring the argument order for redirect. statusCode is optional so it should be after the required url param | ||
@@ -63,0 +60,0 @@ redirect(statusCode: number, url: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; |
@@ -5,3 +5,3 @@ import { ErrorObject } from '@fastify/ajv-compiler' | ||
import { FastifyBaseLogger } from './logger' | ||
import { RouteGenericInterface, FastifyRouteConfig } from './route' | ||
import { RouteGenericInterface, FastifyRouteConfig, RouteHandlerMethod } from './route' | ||
import { FastifySchema } from './schema' | ||
@@ -35,2 +35,3 @@ import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider' | ||
schema: SchemaCompiler; | ||
handler: RouteHandlerMethod; | ||
} | ||
@@ -37,0 +38,0 @@ |
import { FastifyError } from '@fastify/error' | ||
import { ConstraintStrategy } from 'find-my-way' | ||
import { FastifyRequestContext } from './context' | ||
import { onErrorHookHandler, onRequestAbortHookHandler, onRequestHookHandler, onResponseHookHandler, onSendHookHandler, onTimeoutHookHandler, preHandlerHookHandler, preParsingHookHandler, preSerializationHookHandler, preValidationHookHandler } from './hooks' | ||
import { onErrorMetaHookHandler, onRequestAbortMetaHookHandler, onRequestMetaHookHandler, onResponseMetaHookHandler, onSendMetaHookHandler, onTimeoutMetaHookHandler, preHandlerMetaHookHandler, preParsingMetaHookHandler, preSerializationMetaHookHandler, preValidationMetaHookHandler } from './hooks' | ||
import { FastifyInstance } from './instance' | ||
@@ -23,2 +24,12 @@ import { FastifyBaseLogger, FastifyChildLoggerFactory, LogLevel } from './logger' | ||
export type RouteConstraintType = Omit<ConstraintStrategy<any>, 'deriveConstraint'> & { | ||
deriveConstraint<Context>(req: RawRequestDefaultExpression<RawServerDefault>, ctx?: Context, done?: (err: Error, ...args: any) => any): any, | ||
} | ||
export interface RouteConstraint { | ||
version?: string | ||
host?: RegExp | string | ||
[name: string]: unknown | ||
} | ||
/** | ||
@@ -47,3 +58,3 @@ * Route shorthand options for the various shorthand methods | ||
version?: string; | ||
constraints?: { [name: string]: any }, | ||
constraints?: RouteConstraint, | ||
prefixTrailingSlash?: 'slash'|'no-slash'|'both'; | ||
@@ -60,24 +71,23 @@ errorHandler?: ( | ||
// hooks | ||
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> | ||
| onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>[]; | ||
onRequestAbort?: onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onRequest?: onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preParsing?: preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preValidation?: preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preHandler?: preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
preSerialization?: preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onSend?: onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onResponse?: onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onTimeout?: onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
onError?: onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> | ||
| onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>[]; | ||
onRequestAbort?: onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
| onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]; | ||
} | ||
/** | ||
@@ -126,4 +136,5 @@ * Route handler method declaration. | ||
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, | ||
Logger extends FastifyBaseLogger = FastifyBaseLogger | ||
> { | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>( | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>( | ||
path: string, | ||
@@ -133,7 +144,7 @@ opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>, | ||
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>( | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>( | ||
path: string, | ||
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | ||
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>; | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>( | ||
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>( | ||
path: string, | ||
@@ -140,0 +151,0 @@ opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> |
@@ -81,1 +81,11 @@ import * as http from 'http' | ||
: Input; | ||
type OmitIndexSignature<T> = { | ||
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; | ||
}; | ||
/** | ||
* HTTP header strings | ||
* Use this type only for input values, not for output values. | ||
*/ | ||
export type HttpHeader = keyof OmitIndexSignature<http.OutgoingHttpHeaders> | (string & Record<never, never>); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2373031
324
56633
408
1
- Removedprocess-warning@2.3.2(transitive)
Updatedpino@^8.17.0
Updatedprocess-warning@^3.0.0