@@ -140,15 +140,7 @@ export class Config {
140140 throw 'extendSessionOnUse must be a boolean value' ;
141141 }
142142
143- if ( publicServerURL ) {
144- if (
145- typeof publicServerURL !== 'function' &&
146- ! publicServerURL . startsWith ( 'http://' ) &&
147- ! publicServerURL . startsWith ( 'https://' )
148- ) {
149- throw 'publicServerURL should be a valid HTTPS URL starting with https://' ;
150- }
151- }
143+ this . validatePublicServerURL ( { publicServerURL } ) ;
152144 this . validateSessionConfiguration ( sessionLength , expireInactiveSessions ) ;
153145 this . validateIps ( 'masterKeyIps' , masterKeyIps ) ;
154146 this . validateIps ( 'maintenanceKeyIps' , maintenanceKeyIps ) ;
@@ -462,6 +454,27 @@ export class Config {
462454 }
463455 }
464456
457+ static validatePublicServerURL ( { publicServerURL, required = false } ) {
458+ if ( ! publicServerURL && required ) {
459+ throw 'The option publicServerURL is required.' ;
460+ }
461+
462+ const type = typeof publicServerURL ;
463+
464+ if ( type === 'string' ) {
465+ if ( ! publicServerURL . startsWith ( 'http://' ) && ! publicServerURL . startsWith ( 'https://' ) ) {
466+ throw 'The option publicServerURL must be a valid URL starting with http:// or https://.' ;
467+ }
468+ return ;
469+ }
470+
471+ if ( type === 'function' ) {
472+ return ;
473+ }
474+
475+ throw `The option publicServerURL must be a string or function, but got ${ type } .` ;
476+ }
477+
465478 static validateEmailConfiguration ( {
466479 emailAdapter,
467480 appName,
@@ -475,9 +488,7 @@ export class Config {
475488 if ( typeof appName !== 'string' ) {
476489 throw 'An app name is required for e-mail verification and password resets.' ;
477490 }
478- if ( typeof publicServerURL !== 'string' && typeof publicServerURL !== 'function' ) {
479- throw 'A public server url is required for e-mail verification and password resets.' ;
480- }
491+ this . validatePublicServerURL ( { publicServerURL, required : true } ) ;
481492 if ( emailVerifyTokenValidityDuration ) {
482493 if ( isNaN ( emailVerifyTokenValidityDuration ) ) {
483494 throw 'Email verify token validity duration must be a valid number.' ;
0 commit comments