mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-24 06:03:28 -05:00
refactor: use process.env in node environments (#51110)
This commit is contained in:
committed by
GitHub
parent
c2fff83d41
commit
5f475cefa6
@@ -1,11 +1,14 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { allowedOrigins } = require('../../../../config/cors-settings');
|
||||
// homeLocation is being used as a fallback here. If the one provided by the
|
||||
// client is invalid we default to this.
|
||||
const { homeLocation } = require('../../../../config/env.json');
|
||||
// process.env.HOME_LOCATION is being used as a fallback here. If the one
|
||||
// provided by the client is invalid we default to this.
|
||||
const { availableLangs } = require('../../../../config/i18n');
|
||||
|
||||
function getReturnTo(encryptedParams, secret, _homeLocation = homeLocation) {
|
||||
function getReturnTo(
|
||||
encryptedParams,
|
||||
secret,
|
||||
_homeLocation = process.env.HOME_LOCATION
|
||||
) {
|
||||
let params;
|
||||
try {
|
||||
params = jwt.verify(encryptedParams, secret);
|
||||
@@ -25,7 +28,7 @@ function getReturnTo(encryptedParams, secret, _homeLocation = homeLocation) {
|
||||
|
||||
function normalizeParams(
|
||||
{ returnTo, origin, pathPrefix },
|
||||
_homeLocation = homeLocation
|
||||
_homeLocation = process.env.HOME_LOCATION
|
||||
) {
|
||||
// coerce to strings, just in case something weird and nefarious is happening
|
||||
returnTo = '' + returnTo;
|
||||
@@ -59,7 +62,7 @@ function getRedirectParams(req, _normalizeParams = normalizeParams) {
|
||||
const url = req.header('Referer');
|
||||
// since we do not always redirect the user back to the page they were on
|
||||
// we need client locale and origin to construct the redirect url.
|
||||
const returnUrl = new URL(url ? url : homeLocation);
|
||||
const returnUrl = new URL(url ? url : process.env.HOME_LOCATION);
|
||||
const origin = returnUrl.origin;
|
||||
// if this is not one of the client languages, validation will convert
|
||||
// this to '' before it is used.
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('redirection', () => {
|
||||
expect(keys.length).toBe(3);
|
||||
expect(keys).toEqual(expect.arrayContaining(expectedKeys));
|
||||
});
|
||||
it('should default to homeLocation', () => {
|
||||
it('should default to process.env.HOME_LOCATION', () => {
|
||||
expect.assertions(1);
|
||||
expect(normalizeParams({}, defaultOrigin)).toEqual(defaultObject);
|
||||
});
|
||||
@@ -92,9 +92,9 @@ describe('redirection', () => {
|
||||
);
|
||||
});
|
||||
// we *could*, in principle, grab the path and send them to
|
||||
// homeLocation/path, but if the origin is wrong something unexpected is
|
||||
// process.env.HOME_LOCATION/path, but if the origin is wrong something unexpected is
|
||||
// going on. In that case it's probably best to just send them to
|
||||
// homeLocation/learn.
|
||||
// process.env.HOME_LOCATION/learn.
|
||||
it('should return default parameters if the origin is unknown', () => {
|
||||
expect.assertions(1);
|
||||
const exampleOrigin = {
|
||||
|
||||
Reference in New Issue
Block a user