diff --git a/.changeset/fuzzy-bears-nail.md b/.changeset/fuzzy-bears-nail.md new file mode 100644 index 00000000..63ed407a --- /dev/null +++ b/.changeset/fuzzy-bears-nail.md @@ -0,0 +1,6 @@ +--- +'@powersync/common': patch +'@powersync/web': patch +--- + +Handle additional forward slash in the POWERSYNC_URL environment variable diff --git a/packages/common/src/client/sync/stream/AbstractRemote.ts b/packages/common/src/client/sync/stream/AbstractRemote.ts index 73cd0a28..abfba091 100644 --- a/packages/common/src/client/sync/stream/AbstractRemote.ts +++ b/packages/common/src/client/sync/stream/AbstractRemote.ts @@ -14,6 +14,7 @@ import { version as POWERSYNC_JS_VERSION } from '../../../../package.json'; export type BSONImplementation = typeof BSON; +const POWERSYNC_TRAILING_SLASH_MATCH = /\/+$/; export type RemoteConnector = { fetchCredentials: () => Promise; }; @@ -108,6 +109,11 @@ export abstract class AbstractRemote { return this.credentials!; } this.credentials = await this.connector.fetchCredentials(); + if (this.credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) { + throw new Error( + `A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.` + ); + } return this.credentials; }