Improves validation of email parameters in Configuration

This commit is contained in:
Florent Vilmart
2016-02-28 00:15:59 -05:00
parent 2183b0be82
commit 6aa38ea8ca
4 changed files with 34 additions and 30 deletions

View File

@@ -39,6 +39,29 @@ export class Config {
this.mount = mount;
}
static validate(options) {
this.validateEmailConfiguration({verifyUserEmails: options.verifyUserEmails,
appName: options.appName,
publicServerURL: options.publicServerURL})
}
static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) {
if (verifyUserEmails) {
if (typeof appName !== 'string') {
throw 'An app name is required when using email verification.';
}
if (!process.env.TESTING && typeof publicServerURL !== 'string') {
if (process.env.NODE_ENV === 'production') {
throw 'A public server url is required when using email verification.';
} else {
console.warn("");
console.warn("You should set publicServerURL to serve the public pages");
console.warn("");
}
}
}
}
get linksServerURL() {
return this.publicServerURL || this.serverURL;
}