- how to intercept the request
- what you can do with the request at this point
5.34.0 version we added a possibility for users to intercept the Fastify request in it’s initial phase.
It can be done via the
With this plugin you can do anything with the Fastify’s Request object, even stop the request from being processed. To find out why you can stop the request from being processed, read about it in the Fastify Lifecycle and Fastify Hooks documentation.
Of course, as with our other plugins, you must register it in the Lambda handler plugins array:
By default, Webiny intercepts the
OPTIONS request and stop all of the Fastify lifecycles, after the
onRequest, from being ran.
We do this because we have no need to run all the code we usually run for, eg.,
You can see the code here.
HandlerOnRequestPlugin, users can prevent our default behavior.
The most simple answer would be: to output their own headers in the
To prevent the Webiny default behavior on
OPTIONS request, user would need to add a simple plugin which returns
false as the result.
Here is an example of sending a custom header
myCustomHeader, and prevent the Webiny default behavior, on
Simply, with the
HandlerOnRequestPlugin user can, in the initial stage of the Fastify Request Lifecycle:
- intercept the request and prevent it to go further down the lifecycle line
- modify the Webiny default
OPTIONSheaders output to suit their own need
- log the request to some outside service
Users must be careful on which path are they when executing the plugin code. Webiny has one built-in path: