feat(server): Add URL utils to compute server URL, HOST, PORT, etc.
parent
d313ab68e4
commit
2321f7b326
|
@ -10,12 +10,16 @@ import loopback from 'loopback';
|
||||||
import { saveUser, observeMethod } from '../../server/utils/rx.js';
|
import { saveUser, observeMethod } from '../../server/utils/rx.js';
|
||||||
import { blacklistedUsernames } from '../../server/utils/constants.js';
|
import { blacklistedUsernames } from '../../server/utils/constants.js';
|
||||||
import { wrapHandledError } from '../../server/utils/create-handled-error.js';
|
import { wrapHandledError } from '../../server/utils/create-handled-error.js';
|
||||||
|
import {
|
||||||
|
getServerFullURL,
|
||||||
|
getEmailSender,
|
||||||
|
getProtocol,
|
||||||
|
getHost,
|
||||||
|
getPort
|
||||||
|
} from '../../server/utils/url-utils.js';
|
||||||
|
|
||||||
const debug = debugFactory('fcc:user:remote');
|
const debug = debugFactory('fcc:user:remote');
|
||||||
const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
|
const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
|
||||||
const isDev = process.env.NODE_ENV !== 'production';
|
|
||||||
const devHost = process.env.HOST || 'localhost';
|
|
||||||
const emailSender = process.env.EMAIL_SENDER || 'team@freecodecamp.org';
|
|
||||||
|
|
||||||
const createEmailError = () => new Error(
|
const createEmailError = () => new Error(
|
||||||
'Please check to make sure the email is a valid email address.'
|
'Please check to make sure the email is a valid email address.'
|
||||||
|
@ -592,11 +596,11 @@ module.exports = function(User) {
|
||||||
|
|
||||||
const { id: loginToken } = token;
|
const { id: loginToken } = token;
|
||||||
const loginEmail = user.email;
|
const loginEmail = user.email;
|
||||||
|
const host = getServerFullURL();
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
type: 'email',
|
type: 'email',
|
||||||
to: user.email,
|
to: user.email,
|
||||||
from: emailSender,
|
from: getEmailSender(),
|
||||||
subject: 'freeCodeCamp - Authentication Request!',
|
subject: 'freeCodeCamp - Authentication Request!',
|
||||||
text: renderAuthEmail({
|
text: renderAuthEmail({
|
||||||
loginEmail,
|
loginEmail,
|
||||||
|
@ -697,11 +701,11 @@ module.exports = function(User) {
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
type: 'email',
|
type: 'email',
|
||||||
to: email,
|
to: email,
|
||||||
from: emailSender,
|
from: getEmailSender(),
|
||||||
subject: 'freeCodeCamp - Email Update Requested',
|
subject: 'freeCodeCamp - Email Update Requested',
|
||||||
protocol: isDev ? null : 'https',
|
protocol: getProtocol(),
|
||||||
host: isDev ? devHost : 'freecodecamp.org',
|
host: getHost(),
|
||||||
port: isDev ? null : 443,
|
port: getPort(),
|
||||||
template: path.join(
|
template: path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
'..',
|
'..',
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
const isDev = process.env.NODE_ENV !== 'production';
|
||||||
|
const isBeta = !!process.env.BETA;
|
||||||
|
|
||||||
|
export function getEmailSender() {
|
||||||
|
return process.env.EMAIL_SENDER || 'team@freecodecamp.com';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPort() {
|
||||||
|
if (!isDev) {
|
||||||
|
return '443';
|
||||||
|
}
|
||||||
|
return process.env.SYNC_PORT || '3000';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProtocol() {
|
||||||
|
return isDev ? 'http' : 'https';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHost() {
|
||||||
|
if (isDev) {
|
||||||
|
return process.env.HOST || 'localhost';
|
||||||
|
}
|
||||||
|
return isBeta ? 'beta.freecodecamp.com' : 'freecodecamp.com';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getServerFullURL() {
|
||||||
|
if (!isDev) {
|
||||||
|
return getProtocol()
|
||||||
|
+ '://'
|
||||||
|
+ getHost();
|
||||||
|
}
|
||||||
|
return getProtocol()
|
||||||
|
+ '://'
|
||||||
|
+ getHost()
|
||||||
|
+ ':'
|
||||||
|
+ getPort();
|
||||||
|
}
|
Loading…
Reference in New Issue