Skip to content

Commit

Permalink
modify execution order of nitro plugins
Browse files Browse the repository at this point in the history
- put our security plugins last
- allows to insert nonces after all external scripts have been inserted
  • Loading branch information
vejja committed Oct 28, 2023
1 parent 3e596bc commit 9d26803
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,29 @@ const registerSecurityNitroPlugins = (
)
}
})

// Make sure our nitro plugins will be applied last
// After all other third-party modules that might have loaded their own nitro plugins
nuxt.hook('nitro:init', nitro => {
const securityPluginsPrefix = normalize(
fileURLToPath(
new URL('./runtime/nitro/plugins', import.meta.url)
)
)
nitro.options.plugins.sort((a, b) => {
if (a.startsWith(securityPluginsPrefix)) {
if (b.startsWith(securityPluginsPrefix)) {
return 0
} else {
return 1
}
} else {
if (b.startsWith(securityPluginsPrefix)) {
return -1
} else {
return 0
}
}
})
})
}

0 comments on commit 9d26803

Please sign in to comment.