@@ -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,16 +57,33 @@ export class Config {
5657 return config ;
5758 }
5859
59- async getPublicServerURL ( ) {
60- if ( typeof this . publicServerURL === 'function' ) {
61- return await this . publicServerURL ( ) ;
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+ AppCache . put ( this . appId , 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+ }
6280 }
63- return this . publicServerURL ;
6481 }
6582
6683 static put ( serverConfiguration ) {
6784 Config . validateOptions ( serverConfiguration ) ;
6885 Config . validateControllers ( serverConfiguration ) ;
86+ Config . transformConfiguration ( serverConfiguration ) ;
6987 AppCache . put ( serverConfiguration . appId , serverConfiguration ) ;
7088 Config . setupPasswordValidator ( serverConfiguration . passwordPolicy ) ;
7189 return serverConfiguration ;
@@ -456,7 +474,7 @@ export class Config {
456474 if ( typeof appName !== 'string' ) {
457475 throw 'An app name is required for e-mail verification and password resets.' ;
458476 }
459- if ( ! publicServerURL || ( typeof publicServerURL !== 'string' && typeof publicServerURL !== 'function' ) ) {
477+ if ( typeof publicServerURL !== 'string' ) {
460478 throw 'A public server url is required for e-mail verification and password resets.' ;
461479 }
462480 if ( emailVerifyTokenValidityDuration ) {
@@ -528,7 +546,11 @@ export class Config {
528546 }
529547
530548 get mount ( ) {
531- return this . _mount ;
549+ var mount = this . _mount ;
550+ if ( this . publicServerURL ) {
551+ mount = this . publicServerURL ;
552+ }
553+ return mount ;
532554 }
533555
534556 set mount ( newValue ) {
@@ -692,64 +714,55 @@ export class Config {
692714 }
693715 }
694716
695- async invalidLinkURL ( ) {
696- const publicServerURL = await this . getPublicServerURL ( ) ;
697- return this . customPages . invalidLink || `${ publicServerURL } /apps/invalid_link.html` ;
717+ get invalidLinkURL ( ) {
718+ return this . customPages . invalidLink || `${ this . publicServerURL } /apps/invalid_link.html` ;
698719 }
699720
700- async invalidVerificationLinkURL ( ) {
701- const publicServerURL = await this . getPublicServerURL ( ) ;
721+ get invalidVerificationLinkURL ( ) {
702722 return (
703723 this . customPages . invalidVerificationLink ||
704- `${ publicServerURL } /apps/invalid_verification_link.html`
724+ `${ this . publicServerURL } /apps/invalid_verification_link.html`
705725 ) ;
706726 }
707727
708- async linkSendSuccessURL ( ) {
709- const publicServerURL = await this . getPublicServerURL ( ) ;
728+ get linkSendSuccessURL ( ) {
710729 return (
711- this . customPages . linkSendSuccess || `${ publicServerURL } /apps/link_send_success.html`
730+ this . customPages . linkSendSuccess || `${ this . publicServerURL } /apps/link_send_success.html`
712731 ) ;
713732 }
714733
715- async linkSendFailURL ( ) {
716- const publicServerURL = await this . getPublicServerURL ( ) ;
717- return this . customPages . linkSendFail || `${ publicServerURL } /apps/link_send_fail.html` ;
734+ get linkSendFailURL ( ) {
735+ return this . customPages . linkSendFail || `${ this . publicServerURL } /apps/link_send_fail.html` ;
718736 }
719737
720- async verifyEmailSuccessURL ( ) {
721- const publicServerURL = await this . getPublicServerURL ( ) ;
738+ get verifyEmailSuccessURL ( ) {
722739 return (
723740 this . customPages . verifyEmailSuccess ||
724- `${ publicServerURL } /apps/verify_email_success.html`
741+ `${ this . publicServerURL } /apps/verify_email_success.html`
725742 ) ;
726743 }
727744
728- async choosePasswordURL ( ) {
729- const publicServerURL = await this . getPublicServerURL ( ) ;
730- return this . customPages . choosePassword || `${ publicServerURL } /apps/choose_password` ;
745+ get choosePasswordURL ( ) {
746+ return this . customPages . choosePassword || `${ this . publicServerURL } /apps/choose_password` ;
731747 }
732748
733- async requestResetPasswordURL ( ) {
734- const publicServerURL = await this . getPublicServerURL ( ) ;
735- return `${ publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /request_password_reset` ;
749+ get requestResetPasswordURL ( ) {
750+ return `${ this . publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /request_password_reset` ;
736751 }
737752
738- async passwordResetSuccessURL ( ) {
739- const publicServerURL = await this . getPublicServerURL ( ) ;
753+ get passwordResetSuccessURL ( ) {
740754 return (
741755 this . customPages . passwordResetSuccess ||
742- `${ publicServerURL } /apps/password_reset_success.html`
756+ `${ this . publicServerURL } /apps/password_reset_success.html`
743757 ) ;
744758 }
745759
746760 get parseFrameURL ( ) {
747761 return this . customPages . parseFrameURL ;
748762 }
749763
750- async verifyEmailURL ( ) {
751- const publicServerURL = await this . getPublicServerURL ( ) ;
752- return `${ publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /verify_email` ;
764+ get verifyEmailURL ( ) {
765+ return `${ this . publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /verify_email` ;
753766 }
754767
755768 async loadMasterKey ( ) {
0 commit comments