Skip to content

Commit

Permalink
removed whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
donneypr committed Dec 24, 2024
1 parent 032708c commit a2c68e1
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions desktop-app/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ const createWindow = async () => {

// Add BROWSER_SYNC_HOST to the allowed Content-Security-Policy origins
mainWindow.webContents.session.webRequest.onHeadersReceived(
async (details, callback) => {
(details, callback) => {
const cspKey = 'content-security-policy';

// Ensure responseHeaders and cspKey exist
if (details.responseHeaders?.[cspKey]) {
const cspHeader = details.responseHeaders[cspKey][0];

const cspHeader = details.responseHeaders[cspKey]?.[0] || '';
// Define the rules to replace dynamically
const replacements: Record<string, string> = {
'default-src': `default-src ${BROWSER_SYNC_HOST}`,
Expand All @@ -156,21 +155,19 @@ const createWindow = async () => {
'child-src': `child-src ${BROWSER_SYNC_HOST}`,
'worker-src': `worker-src ${BROWSER_SYNC_HOST}`,
};

// Apply replacements
// Apply replacements dynamically
const updatedCSPHeader = Object.entries(replacements).reduce(
(header, [key, value]) => header.replace(key, value),
(header, [key, value]) => (header ? header.replace(key, value) : ''),
cspHeader
);

// Update the response headers
details.responseHeaders[cspKey][0] = updatedCSPHeader;
}

// Callback with updated headers
callback({ responseHeaders: details.responseHeaders });
}
);

Check failure on line 170 in desktop-app/src/main/main.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest)

Delete `··`
mainWindow.loadURL(
`${resolveHtmlPath('index.html')}?urlToOpen=${encodeURI(
urlToOpen ?? 'undefined'
Expand Down

0 comments on commit a2c68e1

Please sign in to comment.