fastify-normalize-request-reply
v2.2.1
Published
A Fastify plugin to normalize the request and reply to Express request and response
Downloads
56
Maintainers
Readme
fastify-normalize-request-reply
NOTE
This plugin will not be updated for version Fastify 3.x, because of the internal changes that where made for how middleware is implemented in Fastify now.
NOTE
This plugin does not support Express middleware that goes beyond simple request and response interaction. If the Express middleware has a UI with a template engine view; utilizes the Express routers; or starts its own instance of Express, then it is not supported.
Description
A plugin for Fastify version 2.x that utilizes the Hook onRequest with addHook to normalize the Fastify request and reply to the Express version 4.x request and response. This allows middleware with interaction with the request and response that was originally written for Express to be be utilized within Fastify.
Install
npm install --save fastify-normalize-request-reply
Usage
Add it to you project with register
and you are done!
// Register the plugin
fastify.register(require('fastify-normalize-request-reply'));
Options
This plugin allows specifying options that are normally available to the Express request and response through Application Settings:
env
: String : Environment mode. Be sure to set toproduction
in a production environment. (process.env.NODE_ENV
ordevelopment
, if NODE_ENV environment variable is not set, by default)etag
: Varied : Set the ETag response header. For possible values, see the etag options table. (weak
by default)json escape
: Boolean : Enable escaping JSON responses from the res.json, res.jsonp, and res.send APIs. This will escape the characters <, >, and & as Unicode escape sequences in JSON. (N/A - undefined
by default)json replacer
: Varied : Thereplacer
argument used byJSON.stringify
. (N/A - undefined
by default)json spaces
: Varied : Thespace
argument used byJSON.stringify
. This is typically set to the number of spaces to use to indent prettified JSON. (N/A - undefined
by default)jsonp callback name
: String : Specifies the default JSONP callback name. (callback
by default)query parser
: Varied : Disable query parsing by setting the value tofalse
, or set the query parser to use eithersimple
orextended
or a custom query string parsingfunction
. (extended
by default)subdomain offset
: Number : The number of dot-separated parts of the host to remove to access subdomain. (2
by default)trust proxy
: Varied : Indicates the server is behind a front-facing proxy, and to use the X-Forwarded-* headers to determine the connection and the IP address of the client. To enable it, use the values described in the trust proxy options table. (false - disabled
by default)
License
Licensed under MIT