There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(electron): add refer/origin to api requests (#9880)
pengx173834699c6851
diff --git a/packages/frontend/apps/electron/scripts/dev.ts b/packages/frontend/apps/electron/scripts/dev.tsindex b1e6be6c72..cfedec5740 100644--- a/packages/frontend/apps/electron/scripts/dev.ts+++ b/packages/frontend/apps/electron/scripts/dev.ts@@ -40,7 +40,7 @@ function spawnOrReloadElectron() {process.env.NODE_OPTIONS = NODE_OPTIONS.replace(/--import=[^\s]*/, '');}- spawnProcess = spawn(exe, ['.'], {+ spawnProcess = spawn(exe, ['.', '--inspect'], {cwd: electronDir,env: process.env,shell: true,diff --git a/packages/frontend/apps/electron/src/main/constants.ts b/packages/frontend/apps/electron/src/main/constants.tsindex eecbb1c705..d14d55cbef 100644--- a/packages/frontend/apps/electron/src/main/constants.ts+++ b/packages/frontend/apps/electron/src/main/constants.ts@@ -1,4 +1,4 @@-export const mainWindowOrigin = process.env.DEV_SERVER_URL || 'file://.';+export const mainWindowOrigin = 'file://.';export const onboardingViewUrl = `${mainWindowOrigin}${mainWindowOrigin.endsWith('/') ? '' : '/'}onboarding`;export const shellViewUrl = `${mainWindowOrigin}${mainWindowOrigin.endsWith('/') ? '' : '/'}shell.html`;export const backgroundWorkerViewUrl = `${mainWindowOrigin}${mainWindowOrigin.endsWith('/') ? '' : '/'}background-worker.html`;diff --git a/packages/frontend/apps/electron/src/main/protocol.ts b/packages/frontend/apps/electron/src/main/protocol.tsindex 8c6c1ad5f1..4597a895b1 100644--- a/packages/frontend/apps/electron/src/main/protocol.ts+++ b/packages/frontend/apps/electron/src/main/protocol.ts@@ -41,10 +41,19 @@ function isNetworkResource(pathname: string) {}async function handleFileRequest(request: Request) {+ const urlObject = new URL(request.url);++ // Redirect to webpack dev server if defined+ if (process.env.DEV_SERVER_URL) {+ const devServerUrl = new URL(+ urlObject.pathname,+ process.env.DEV_SERVER_URL+ );+ return net.fetch(devServerUrl.toString(), request);+ }const clonedRequest = Object.assign(request.clone(), {bypassCustomProtocolHandlers: true,});- const urlObject = new URL(request.url);// this will be file types (in the web-static folder)let filepath = '';// if is a file type, load the file in resources@@ -181,6 +190,12 @@ export function registerProtocol() {.join('; ');delete details.requestHeaders['cookie'];details.requestHeaders['Cookie'] = cookieString;++ // mitigate the issue of the worker not being able to access the origin+ if (isNetworkResource(pathname)) {+ details.requestHeaders['origin'] = url.origin;+ details.requestHeaders['referer'] = url.origin;+ }}})().catch(err => {diff --git a/packages/frontend/apps/electron/src/main/security-restrictions.ts b/packages/frontend/apps/electron/src/main/security-restrictions.tsindex c851c7e5b4..4d14daf7e1 100644--- a/packages/frontend/apps/electron/src/main/security-restrictions.ts+++ b/packages/frontend/apps/electron/src/main/security-restrictions.ts@@ -2,12 +2,7 @@ import { app, shell } from 'electron';app.on('web-contents-created', (_, contents) => {const isInternalUrl = (url: string) => {- return (- (process.env.DEV_SERVER_URL &&- url.startsWith(process.env.DEV_SERVER_URL)) ||- url.startsWith('affine://') ||- url.startsWith('file://.')- );+ return url.startsWith('file://.');};/*** Block navigation to origins not on the allowlist.