Skip to content

Commit

Permalink
fix: update name for variable and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulTinku committed Feb 29, 2024
1 parent 3ba4a21 commit bf136f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/subapp-server/lib/fastify-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function makeRouteHandler({ path, routeRenderer, routeOptions }) {

let cspHeader;
/** If csp headers are provided by application in route options then use that otherwise generate CSP headers */
if(routeOptions.getCSPHeader && typeof routeOptions.getCSPHeader === "function"){
const rawCSPHeader = routeOptions.getCSPHeader({ styleNonce, scriptNonce });
if(routeOptions.cspHeaderValues instanceof Function ){
const rawCSPHeader = routeOptions.cspHeaderValues({ styleNonce, scriptNonce });
// Replace newline characters and spaces
cspHeader = rawCSPHeader.replace(/\s{2,}/g, " ").trim();
}else{
Expand Down
4 changes: 1 addition & 3 deletions samples/poc-subappv1-csp/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const setCSPHeaderValues = ({styleNonce, scriptNonce}) => {
* Option 3 - Selectively set boolean flag for `cspNonce`. { style: true } will add nonce only
* for styles
*
* Option 4 - write a function which would return list of CSP directives and values as string
* and pass that "function" to getCSPHeader
*/

export default {
Expand All @@ -49,7 +47,7 @@ export default {
cspNonce: true,
// cspNonce: { style: true }, // { script: true }
// cspNonce: cspNonceValue,
getCSPHeader: setCSPHeaderValues,
cspHeaderValues: setCSPHeaderValues,
criticalCSS: path.join(__dirname, "./server/critical.css"),
...commonRouteOptions
}
Expand Down

0 comments on commit bf136f0

Please sign in to comment.