44
55import cache from './cache' ;
66
7+ function removeTrailingSlash ( str ) {
8+ if ( ! str ) {
9+ return str ;
10+ }
11+ if ( str . endsWith ( "/" ) ) {
12+ str = str . substr ( 0 , str . length - 1 ) ;
13+ }
14+ return str ;
15+ }
16+
717export class Config {
818 constructor ( applicationId : string , mount : string ) {
919 let DatabaseAdapter = require ( './DatabaseAdapter' ) ;
@@ -24,7 +34,7 @@ export class Config {
2434 this . database = DatabaseAdapter . getDatabaseConnection ( applicationId , cacheInfo . collectionPrefix ) ;
2535
2636 this . serverURL = cacheInfo . serverURL ;
27- this . publicServerURL = cacheInfo . publicServerURL ;
37+ this . publicServerURL = removeTrailingSlash ( cacheInfo . publicServerURL ) ;
2838 this . verifyUserEmails = cacheInfo . verifyUserEmails ;
2939 this . appName = cacheInfo . appName ;
3040
@@ -35,14 +45,19 @@ export class Config {
3545 this . userController = cacheInfo . userController ;
3646 this . authDataManager = cacheInfo . authDataManager ;
3747 this . customPages = cacheInfo . customPages || { } ;
38- this . mount = mount ;
48+ this . mount = removeTrailingSlash ( mount ) ;
3949 this . liveQueryController = cacheInfo . liveQueryController ;
4050 }
4151
4252 static validate ( options ) {
4353 this . validateEmailConfiguration ( { verifyUserEmails : options . verifyUserEmails ,
4454 appName : options . appName ,
4555 publicServerURL : options . publicServerURL } )
56+ if ( options . publicServerURL ) {
57+ if ( ! options . publicServerURL . startsWith ( "http://" ) && ! options . publicServerURL . startsWith ( "https://" ) ) {
58+ throw "publicServerURL should be a valid HTTPS URL starting with https://"
59+ }
60+ }
4661 }
4762
4863 static validateEmailConfiguration ( { verifyUserEmails, appName, publicServerURL} ) {
@@ -56,6 +71,18 @@ export class Config {
5671 }
5772 }
5873
74+ get mount ( ) {
75+ var mount = this . _mount ;
76+ if ( this . publicServerURL ) {
77+ mount = this . publicServerURL ;
78+ }
79+ return mount ;
80+ }
81+
82+ set mount ( newValue ) {
83+ this . _mount = newValue ;
84+ }
85+
5986 get invalidLinkURL ( ) {
6087 return this . customPages . invalidLink || `${ this . publicServerURL } /apps/invalid_link.html` ;
6188 }
0 commit comments