fix(client,tools): update proxy and location paths (#37106)
This commit is contained in:
@ -10,6 +10,8 @@ const {
|
|||||||
API_LOCATION: api,
|
API_LOCATION: api,
|
||||||
FORUM_LOCATION: forum,
|
FORUM_LOCATION: forum,
|
||||||
NEWS_LOCATION: news,
|
NEWS_LOCATION: news,
|
||||||
|
FORUM_PROXY: forumProxy,
|
||||||
|
NEWS_PROXY: newsProxy,
|
||||||
LOCALE: locale,
|
LOCALE: locale,
|
||||||
STRIPE_PUBLIC: stripePublicKey,
|
STRIPE_PUBLIC: stripePublicKey,
|
||||||
ALGOLIA_APP_ID: algoliaAppId,
|
ALGOLIA_APP_ID: algoliaAppId,
|
||||||
@ -20,7 +22,9 @@ const locations = {
|
|||||||
homeLocation: home,
|
homeLocation: home,
|
||||||
apiLocation: api,
|
apiLocation: api,
|
||||||
forumLocation: forum,
|
forumLocation: forum,
|
||||||
newsLocation: news
|
newsLocation: news,
|
||||||
|
forumProxy: forumProxy,
|
||||||
|
newsProxy: newsProxy
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Object.assign(locations, {
|
module.exports = Object.assign(locations, {
|
||||||
|
@ -29,8 +29,11 @@ IMAGE_BASE_URL='https://s3.amazonaws.com/freecodecamp/images/'
|
|||||||
|
|
||||||
HOME_LOCATION='http://localhost:8000'
|
HOME_LOCATION='http://localhost:8000'
|
||||||
API_LOCATION='http://localhost:3000'
|
API_LOCATION='http://localhost:3000'
|
||||||
FORUM_LOCATION='https://forum.localhost'
|
FORUM_LOCATION='https://localhost/forum'
|
||||||
NEWS_LOCATION='https://news.localhost/latest'
|
NEWS_LOCATION='https://localhost/news'
|
||||||
|
FORUM_PROXY='https://forum.localhost'
|
||||||
|
NEWS_PROXY='https://news.localhost'
|
||||||
|
|
||||||
LOCALE=english
|
LOCALE=english
|
||||||
|
|
||||||
TEST_CHALLENGES_FOR_LANGS=english
|
TEST_CHALLENGES_FOR_LANGS=english
|
||||||
|
@ -3,22 +3,22 @@ const newsPlaceholderRE = /#\{\{NEWS\}\}/g;
|
|||||||
const forumPlacehilderRE = /#\{\{FORUM\}\}/g;
|
const forumPlacehilderRE = /#\{\{FORUM\}\}/g;
|
||||||
|
|
||||||
exports.createRedirects = function createRedirects(locations) {
|
exports.createRedirects = function createRedirects(locations) {
|
||||||
const { api, news, forum } = locations;
|
const { api, newsProxy, forumProxy } = locations;
|
||||||
|
|
||||||
if (!(api && news && forum)) {
|
if (!(api && newsProxy && forumProxy)) {
|
||||||
throw new Error(`One or more locations are missing, all are required.
|
throw new Error(`One or more locations are missing, all are required.
|
||||||
|
|
||||||
api: ${api}
|
api: ${api}
|
||||||
news: ${news}
|
newsProxy: ${newsProxy}
|
||||||
forum: ${forum}
|
forumProxy: ${forumProxy}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return template
|
return template
|
||||||
.replace(apiPlaceholderRE, api)
|
.replace(apiPlaceholderRE, api)
|
||||||
.replace(newsPlaceholderRE, news)
|
.replace(newsPlaceholderRE, newsProxy)
|
||||||
.replace(forumPlacehilderRE, forum);
|
.replace(forumPlacehilderRE, forumProxy);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
|
@ -4,8 +4,8 @@ const { createRedirects } = require('./create-redirects');
|
|||||||
|
|
||||||
const testLocations = {
|
const testLocations = {
|
||||||
api: 'https://api.example.com',
|
api: 'https://api.example.com',
|
||||||
news: 'https://news.example.com',
|
newsProxy: 'https://news.example.com',
|
||||||
forum: 'https://forum.example.com'
|
forumProxy: 'https://forum.example.com'
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('createRedirects', () => {
|
describe('createRedirects', () => {
|
||||||
@ -33,21 +33,21 @@ describe('createRedirects', () => {
|
|||||||
expect(hasNewsPlaceholder).toBe(false);
|
expect(hasNewsPlaceholder).toBe(false);
|
||||||
expect(hasForumPlaceholder).toBe(false);
|
expect(hasForumPlaceholder).toBe(false);
|
||||||
|
|
||||||
const { api, forum } = testLocations;
|
const { api, forumProxy } = testLocations;
|
||||||
expect(redirects.includes(`${api}/internal/:splat`)).toBe(true);
|
expect(redirects.includes(`${api}/internal/:splat`)).toBe(true);
|
||||||
expect(redirects.includes(`${forum}`)).toBe(true);
|
expect(redirects.includes(`${forumProxy}`)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when any location is missing', () => {
|
it('throws when any location is missing', () => {
|
||||||
expect.assertions(3);
|
expect.assertions(3);
|
||||||
|
|
||||||
const api = 'api';
|
const api = 'api';
|
||||||
const news = 'news';
|
const newsProxy = 'newsProxy';
|
||||||
const forum = 'forum';
|
const forumProxy = 'forumProxy';
|
||||||
|
|
||||||
const noApi = { forum, news };
|
const noApi = { forumProxy, newsProxy };
|
||||||
const noNews = { api, forum };
|
const noNews = { api, forumProxy };
|
||||||
const noForum = { api, news };
|
const noForum = { api, newsProxy };
|
||||||
|
|
||||||
expect(() => createRedirects(noApi)).toThrow();
|
expect(() => createRedirects(noApi)).toThrow();
|
||||||
expect(() => createRedirects(noNews)).toThrow();
|
expect(() => createRedirects(noNews)).toThrow();
|
||||||
|
@ -13,12 +13,7 @@ const log = debug('fcc:tools:ensure-env');
|
|||||||
|
|
||||||
const { FREECODECAMP_NODE_ENV } = process.env;
|
const { FREECODECAMP_NODE_ENV } = process.env;
|
||||||
|
|
||||||
const {
|
const { apiLocation: api, locale, forumProxy, newsProxy } = env;
|
||||||
apiLocation: api,
|
|
||||||
forumLocation: forum,
|
|
||||||
locale,
|
|
||||||
newsLocation: news
|
|
||||||
} = env;
|
|
||||||
|
|
||||||
const apiPath = path.resolve(__dirname, '../../../api-server');
|
const apiPath = path.resolve(__dirname, '../../../api-server');
|
||||||
const clientPath = path.resolve(__dirname, '../../../client');
|
const clientPath = path.resolve(__dirname, '../../../client');
|
||||||
@ -26,7 +21,7 @@ const clientStaticPath = path.resolve(clientPath, 'static');
|
|||||||
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
||||||
|
|
||||||
if (FREECODECAMP_NODE_ENV === 'production') {
|
if (FREECODECAMP_NODE_ENV === 'production') {
|
||||||
const redirects = createRedirects({ api, news, forum });
|
const redirects = createRedirects({ api, newsProxy, forumProxy });
|
||||||
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
log('Error');
|
log('Error');
|
||||||
|
Reference in New Issue
Block a user