@pylonsync/sync 0.3.171 → 0.3.173
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +18 -17
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1262,23 +1262,21 @@ export class SyncEngine {
|
|
|
1262
1262
|
private deriveWsUrl(): string {
|
|
1263
1263
|
const base = this.config.baseUrl;
|
|
1264
1264
|
const url = new URL(base);
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
//
|
|
1269
|
-
//
|
|
1270
|
-
//
|
|
1271
|
-
//
|
|
1272
|
-
// separate WS port to expose, no per-deployment wsUrl env var.
|
|
1265
|
+
const scheme = url.protocol === "https:" ? "wss" : "ws";
|
|
1266
|
+
|
|
1267
|
+
// Always multiplex WS on the same origin via `/api/sync/ws`. The
|
|
1268
|
+
// Pylon runtime accepts the Upgrade on its main HTTP port (4321),
|
|
1269
|
+
// so any reverse proxy that already forwards `/api/*` carries the
|
|
1270
|
+
// WebSocket through too (Vite's `ws: true` proxy, Next.js rewrites,
|
|
1271
|
+
// CDNs with WS support).
|
|
1273
1272
|
//
|
|
1274
|
-
//
|
|
1275
|
-
//
|
|
1276
|
-
//
|
|
1277
|
-
//
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1273
|
+
// The legacy port+1 fallback (`:4322` for a `:4321` API) is still
|
|
1274
|
+
// available on the runtime, but we don't derive it client-side
|
|
1275
|
+
// anymore: any setup where the page origin (e.g. Vite on :3000)
|
|
1276
|
+
// wasn't equal to the API origin would compute ws://localhost:3001
|
|
1277
|
+
// — which doesn't exist and bypasses the dev-server proxy. The
|
|
1278
|
+
// `/api/sync/ws` path goes through whatever proxies `/api/*`,
|
|
1279
|
+
// which is the same code path prod already relies on.
|
|
1282
1280
|
return `${scheme}://${url.host}/api/sync/ws`;
|
|
1283
1281
|
}
|
|
1284
1282
|
|
|
@@ -2385,8 +2383,11 @@ export function createSyncEngine(
|
|
|
2385
2383
|
baseUrl?: string,
|
|
2386
2384
|
options?: Partial<SyncEngineConfig>,
|
|
2387
2385
|
): SyncEngine {
|
|
2386
|
+
// `??` would treat an empty string as "set" — but `init({ baseUrl: "" })`
|
|
2387
|
+
// is the intuitive "use page origin" incantation and must fall back. Use
|
|
2388
|
+
// `||` so undefined/null/"" all route to the auto-detected origin.
|
|
2388
2389
|
const resolved =
|
|
2389
|
-
baseUrl ??
|
|
2390
|
+
(baseUrl && baseUrl.length > 0 ? baseUrl : undefined) ??
|
|
2390
2391
|
(typeof window !== "undefined" && window.location?.origin
|
|
2391
2392
|
? window.location.origin
|
|
2392
2393
|
: "http://localhost:4321");
|