Skip to content

Commit

Permalink
fix nestjs fastify platform warn (#231)
Browse files Browse the repository at this point in the history
* fix nestjs fastify platform warn

* Apply suggestions from code review

Co-authored-by: Gürgün Dayıoğlu <[email protected]>

* fix tests

---------

Co-authored-by: Uzlopak <[email protected]>
Co-authored-by: Gürgün Dayıoğlu <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2023
1 parent d36b175 commit 52a7246
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async function fastifyHelmet (fastify, options) {

fastify.addHook('onRequest', async (request, reply) => {
/* istanbul ignore next */
const { helmet: routeOptions } = request.routeOptions.config || request.context.config
const { helmet: routeOptions } = request.routeOptions?.config ||
request.routeConfig

if (typeof routeOptions !== 'undefined') {
const { enableCSPNonces: enableRouteCSPNonces, skipRoute, ...helmetRouteConfiguration } = routeOptions
Expand All @@ -52,7 +53,8 @@ async function fastifyHelmet (fastify, options) {

fastify.addHook('onRequest', (request, reply, next) => {
/* istanbul ignore next */
const { helmet: routeOptions } = request.routeOptions.config || request.context.config
const { helmet: routeOptions } = request.routeOptions?.config ||
request.routeConfig

if (typeof routeOptions !== 'undefined') {
const { enableCSPNonces: enableRouteCSPNonces, skipRoute, ...helmetRouteConfiguration } = routeOptions
Expand Down
2 changes: 1 addition & 1 deletion test/global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ test('It should not return a fastify `FST_ERR_REP_ALREADY_SENT - Reply already s
}

// We want to crash in the scope of this test
const crash = request.routeOptions.config.fail
const crash = request.routeOptions?.config?.fail || request.routeConfig.fail

Promise.resolve(crash).then((fail) => {
if (fail === true) {
Expand Down

0 comments on commit 52a7246

Please sign in to comment.