[PFX-850] - Fix server middleware stack discrepancies #1011
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
getExpressApp
andgetFastifyApp
An issue was discovered around the implementation/usage of the
getExpressApp
andgetFastifyApp
actions. With the updated patterns of v7, there is an opportunity for theapp
references to have different values at different points in time. By allowing Gasket users to define server routes in multiple places, we then allow for the app reference to contain different values depending on when and where it's referenced.In Gasket v7 we import the
./routes/index.js
into theserver.js
and the route definitions would use an action from one of the plugins.The result:
Reason
The app routes and middleware are applied at different points during the execution of the application. The routes defined in the
./routes/index.js
are declared with theapp
after theprepare
hook(essentially the routes will only have scope/access to the middleware defined in that specific file). Theserver.js
has the same issue, routes declared will only have access to middleware declared in theserver.js
. We then reach thecreateServers -> express -> middleware
hooks and by this time the routes inserver.js
and./routes/index.js
have already been defined with anapp
reference that did not contain the plugin middleware results in the middleware stack.Solution
We are opting to use Gasket functionality to solve this problem. API apps will be generated with a app-level plugin called the
routes-plugin
. The local plugin will hook the server specific lifecycle(express or fastify) and set routes appropriately. The actions associated with retrieving theapp
reference have also been deprecated and their use with thecreateServers
hooks has been removed. Documentation has also been updated and themetadata
entries have been deprecated.Changelog
Test Plan
Tests updated