4
4
5
5
import cache from './cache' ;
6
6
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
+
7
17
export class Config {
8
18
constructor ( applicationId : string , mount : string ) {
9
19
let DatabaseAdapter = require ( './DatabaseAdapter' ) ;
@@ -24,7 +34,7 @@ export class Config {
24
34
this . database = DatabaseAdapter . getDatabaseConnection ( applicationId , cacheInfo . collectionPrefix ) ;
25
35
26
36
this . serverURL = cacheInfo . serverURL ;
27
- this . publicServerURL = cacheInfo . publicServerURL ;
37
+ this . publicServerURL = removeTrailingSlash ( cacheInfo . publicServerURL ) ;
28
38
this . verifyUserEmails = cacheInfo . verifyUserEmails ;
29
39
this . appName = cacheInfo . appName ;
30
40
@@ -35,14 +45,19 @@ export class Config {
35
45
this . userController = cacheInfo . userController ;
36
46
this . authDataManager = cacheInfo . authDataManager ;
37
47
this . customPages = cacheInfo . customPages || { } ;
38
- this . mount = mount ;
48
+ this . mount = removeTrailingSlash ( mount ) ;
39
49
this . liveQueryController = cacheInfo . liveQueryController ;
40
50
}
41
51
42
52
static validate ( options ) {
43
53
this . validateEmailConfiguration ( { verifyUserEmails : options . verifyUserEmails ,
44
54
appName : options . appName ,
45
55
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
+ }
46
61
}
47
62
48
63
static validateEmailConfiguration ( { verifyUserEmails, appName, publicServerURL} ) {
@@ -56,6 +71,18 @@ export class Config {
56
71
}
57
72
}
58
73
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
+
59
86
get invalidLinkURL ( ) {
60
87
return this . customPages . invalidLink || `${ this . publicServerURL } /apps/invalid_link.html` ;
61
88
}
0 commit comments