@@ -32,6 +32,7 @@ function removeTrailingSlash(str) {
3232 return str ;
3333}
3434
35+ const asyncKeys = [ 'publicServerURL' ] ;
3536export class Config {
3637 static get ( applicationId : string , mount : string ) {
3738 const cacheInfo = AppCache . get ( applicationId ) ;
@@ -56,9 +57,33 @@ export class Config {
5657 return config ;
5758 }
5859
60+ async loadKeys ( ) {
61+ const asyncKeys = [ 'publicServerURL' ] ;
62+
63+ await Promise . all (
64+ asyncKeys . map ( async key => {
65+ if ( typeof this [ `_${ key } ` ] === 'function' ) {
66+ this [ key ] = await this [ `_${ key } ` ] ( ) ;
67+ }
68+ } )
69+ ) ;
70+
71+ Config . put ( this ) ;
72+ }
73+
74+ static transformConfiguration ( serverConfiguration ) {
75+ for ( const key of Object . keys ( serverConfiguration ) ) {
76+ if ( asyncKeys . includes ( key ) && typeof serverConfiguration [ key ] === 'function' ) {
77+ serverConfiguration [ `_${ key } ` ] = serverConfiguration [ key ] ;
78+ delete serverConfiguration [ key ] ;
79+ }
80+ }
81+ }
82+
5983 static put ( serverConfiguration ) {
6084 Config . validateOptions ( serverConfiguration ) ;
6185 Config . validateControllers ( serverConfiguration ) ;
86+ Config . transformConfiguration ( serverConfiguration ) ;
6287 AppCache . put ( serverConfiguration . appId , serverConfiguration ) ;
6388 Config . setupPasswordValidator ( serverConfiguration . passwordPolicy ) ;
6489 return serverConfiguration ;
@@ -116,7 +141,11 @@ export class Config {
116141 }
117142
118143 if ( publicServerURL ) {
119- if ( ! publicServerURL . startsWith ( 'http://' ) && ! publicServerURL . startsWith ( 'https://' ) ) {
144+ if (
145+ typeof publicServerURL !== 'function' &&
146+ ! publicServerURL . startsWith ( 'http://' ) &&
147+ ! publicServerURL . startsWith ( 'https://' )
148+ ) {
120149 throw 'publicServerURL should be a valid HTTPS URL starting with https://' ;
121150 }
122151 }
@@ -757,7 +786,6 @@ export class Config {
757786 return this . masterKey ;
758787 }
759788
760-
761789 // TODO: Remove this function once PagesRouter replaces the PublicAPIRouter;
762790 // the (default) endpoint has to be defined in PagesRouter only.
763791 get pagesEndpoint ( ) {
0 commit comments