-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: fix mermaid in production (#6149)
Use dynamic CDN import to use Mermaid as Parcel has issues on handling the static import in production.
- Loading branch information
Showing
2 changed files
with
29 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,13 +41,16 @@ export default function koaSecurityHeaders<StateT, ContextT, ResponseBodyT>( | |
/** Google Sign-In (GSI) origin for Google One Tap. */ | ||
const gsiOrigin = 'https://accounts.google.com/gsi/'; | ||
|
||
// We use react-monaco-editor for code editing in the admin console. It loads the monaco editor asynchronously from a CDN. | ||
// We have the following use cases: | ||
// | ||
// 1. We use `react-monaco-editor` for code editing in the admin console. It loads the monaco | ||
// editor asynchronously from jsDelivr. | ||
// 2. We use `mermaid` for rendering diagrams in the admin console. It loads the mermaid library | ||
// asynchronously from jsDelivr since Parcel has issues with loading it directly in production. | ||
// | ||
// Allow the CDN src in the CSP. | ||
// Allow blob: for monaco editor to load worker scripts | ||
const monacoEditorCDNSource = [ | ||
'https://cdn.jsdelivr.net/npm/[email protected]/min/vs/', | ||
'blob:', | ||
]; | ||
const cdnSources = ['https://cdn.jsdelivr.net/', 'blob:']; | ||
|
||
/** | ||
* Default Applied rules: | ||
|
@@ -122,7 +125,7 @@ export default function koaSecurityHeaders<StateT, ContextT, ResponseBodyT>( | |
scriptSrc: [ | ||
"'self'", | ||
...conditionalArray(!isProduction && ["'unsafe-eval'", "'unsafe-inline'"]), | ||
...monacoEditorCDNSource, | ||
...cdnSources, | ||
], | ||
connectSrc: ["'self'", logtoOrigin, ...adminOrigins, ...coreOrigins, ...developmentOrigins], | ||
// Allow Main Flow origin loaded in preview iframe | ||
|