Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(core): attach custom origin to sync service requests when in tauri (#873)

teo647d8dbb6451
diff --git a/js/app/packages/service-clients/service-sync/client.ts b/js/app/packages/service-clients/service-sync/client.ts
index 705742602b..68a79d795a 100644
--- a/js/app/packages/service-clients/service-sync/client.ts
+++ b/js/app/packages/service-clients/service-sync/client.ts
@@ -11,6 +11,7 @@ import {
type ObjectLike,
ok,
} from '@core/util/maybeResult';
+import { isTauri } from '@core/util/platform';
import { platformFetch } from '@core/util/platformFetch';
import type { SafeFetchInit } from '@core/util/safeFetch';
import type { SerializedEditorState } from 'lexical';
@@ -18,6 +19,11 @@ import { InitializeFromSnapshotRequest } from './generated/schema';
const SYNC_SERVICE_WORKER_URL = `${SYNC_SERVICE_HOSTS['worker']}`;
+const SYNC_ORIGIN =
+ import.meta.env.MODE === 'development'
+ ? 'https://dev.macro.com'
+ : 'https://macro.com';
+
const WAKEUP_TTL = 55 * 1000; // 55 seconds - cloudflare ttl is 60
const pendingWakeups = new Map<string, ReturnType<typeof setTimeout>>();
@@ -37,7 +43,13 @@ export function syncFetch<T extends ObjectLike = never>(
):
| Promise<MaybeResult<FetchWithTokenErrorCode, T>>
| Promise<MaybeError<FetchWithTokenErrorCode>> {
- return fetchWithToken<T>(`${SYNC_SERVICE_WORKER_URL}${url}`, init);
+ return fetchWithToken<T>(`${SYNC_SERVICE_WORKER_URL}${url}`, {
+ ...init,
+ headers: {
+ ...init?.headers,
+ ...(isTauri() && { Origin: SYNC_ORIGIN }),
+ },
+ });
}
type MetadataResponse = {
diff --git a/js/app/tauri/src-tauri/Cargo.toml b/js/app/tauri/src-tauri/Cargo.toml
index 8a99ae7673..606a1e14ed 100644
--- a/js/app/tauri/src-tauri/Cargo.toml
+++ b/js/app/tauri/src-tauri/Cargo.toml
@@ -35,7 +35,7 @@ reqwest = { version = "0.12.23", default-features = false, features = [
serde_qs = "0.15.0"
tauri = { workspace = true, features = [] }
tauri-plugin-deep-link = "2"
-tauri-plugin-http = { git = "https://github.com/seanaye/plugins-workspace", branch = "seanaye/feat/websocket-cookies" }
+tauri-plugin-http = { git = "https://github.com/seanaye/plugins-workspace", branch = "seanaye/feat/websocket-cookies", features = ["unsafe-headers"] }
tauri-plugin-log = { version = "2", features = ["tracing"] }
tauri-plugin-opener = "2"
tauri-plugin-safe-area-insets = "0.1.0"