@@ -11,6 +11,7 @@ import { hash } from '@localfirst/crypto'
11
11
import { debug , memoize , pause } from '@localfirst/shared'
12
12
import { type AbstractConnection } from 'AbstractConnection.js'
13
13
import { AnonymousConnection } from 'AnonymousConnection.js'
14
+ import { buildServerUrl } from 'buildServerUrl.js'
14
15
import { getShareId } from 'getShareId.js'
15
16
import { pack , unpack } from 'msgpackr'
16
17
import { isJoinMessage , type JoinMessage } from 'types.js'
@@ -228,19 +229,18 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
228
229
public async registerTeam ( team : Auth . Team ) {
229
230
await this . addTeam ( team )
230
231
231
- const registrations = this . #server. map ( async url => {
232
- // url could be "localhost:3000" or "syncserver.example.com"
233
- const host = url . split ( ':' ) [ 0 ] // omit port
232
+ const registrations = this . #server. map ( async server => {
233
+ const { origin, hostname } = buildServerUrl ( server )
234
234
235
235
// get the server's public keys
236
- const response = await fetch ( `http:// ${ url } /keys` )
236
+ const response = await fetch ( `${ origin } /keys` )
237
237
const keys = await response . json ( )
238
238
239
239
// add the server's public keys to the team
240
- team . addServer ( { host, keys } )
240
+ team . addServer ( { host : hostname , keys } )
241
241
242
242
// register the team with the server
243
- await fetch ( `http:// ${ url } /teams` , {
243
+ await fetch ( `${ origin } /teams` , {
244
244
method : 'POST' ,
245
245
headers : { 'Content-Type' : 'application/json' } ,
246
246
body : JSON . stringify ( {
@@ -336,8 +336,10 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
336
336
* Registers a share with all of our sync servers.
337
337
*/
338
338
public async registerPublicShare ( shareId : ShareId ) {
339
- const registrations = this . #server. map ( async url => {
340
- await fetch ( `http://${ url } /public-shares` , {
339
+ const registrations = this . #server. map ( async server => {
340
+ const { origin } = buildServerUrl ( server )
341
+
342
+ await fetch ( `${ origin } /public-shares` , {
341
343
method : 'POST' ,
342
344
headers : { 'Content-Type' : 'application/json' } ,
343
345
body : JSON . stringify ( { shareId } ) ,
@@ -625,7 +627,6 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
625
627
#removeConnection( shareId : ShareId , peerId : PeerId ) {
626
628
const connection = this . #connections. get ( [ shareId , peerId ] )
627
629
if ( connection && connection . state !== 'disconnected' ) {
628
- connection . stop ( )
629
630
this . #connections. delete ( [ shareId , peerId ] )
630
631
}
631
632
}
@@ -796,9 +797,9 @@ type Config = {
796
797
797
798
/**
798
799
* If we're using one or more sync servers, we provide their hostnames. The hostname should
799
- * include the domain, as well as the port (if any). It should not include the protocol (e.g.
800
- * `https://` or `ws://`) or any path (e.g. `/sync`). For example, `localhost:3000` or
801
- * ` syncserver.mydomain.com`.
800
+ * include the domain, as well as the port (if any). If you don't include a protocol, we'll
801
+ * assume you want to use http. Any path (e.g. `/sync`) will be ignored.
802
+ * For example, `localhost:3000` or `https:// syncserver.mydomain.com`.
802
803
*/
803
804
server ?: string | string [ ]
804
805
}
0 commit comments