fix(client,tools): update proxy and location paths (#37106)

This commit is contained in:
mrugesh
2019-10-07 16:42:07 -07:00
committed by GitHub
parent 752a3d6d88
commit 4889e0fdc6
5 changed files with 27 additions and 25 deletions

View File

@ -10,6 +10,8 @@ const {
API_LOCATION: api,
FORUM_LOCATION: forum,
NEWS_LOCATION: news,
FORUM_PROXY: forumProxy,
NEWS_PROXY: newsProxy,
LOCALE: locale,
STRIPE_PUBLIC: stripePublicKey,
ALGOLIA_APP_ID: algoliaAppId,
@ -20,7 +22,9 @@ const locations = {
homeLocation: home,
apiLocation: api,
forumLocation: forum,
newsLocation: news
newsLocation: news,
forumProxy: forumProxy,
newsProxy: newsProxy
};
module.exports = Object.assign(locations, {

View File

@ -29,8 +29,11 @@ IMAGE_BASE_URL='https://s3.amazonaws.com/freecodecamp/images/'
HOME_LOCATION='http://localhost:8000'
API_LOCATION='http://localhost:3000'
FORUM_LOCATION='https://forum.localhost'
NEWS_LOCATION='https://news.localhost/latest'
FORUM_LOCATION='https://localhost/forum'
NEWS_LOCATION='https://localhost/news'
FORUM_PROXY='https://forum.localhost'
NEWS_PROXY='https://news.localhost'
LOCALE=english
TEST_CHALLENGES_FOR_LANGS=english

View File

@ -3,22 +3,22 @@ const newsPlaceholderRE = /#\{\{NEWS\}\}/g;
const forumPlacehilderRE = /#\{\{FORUM\}\}/g;
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.
api: ${api}
news: ${news}
forum: ${forum}
newsProxy: ${newsProxy}
forumProxy: ${forumProxy}
`);
}
return template
.replace(apiPlaceholderRE, api)
.replace(newsPlaceholderRE, news)
.replace(forumPlacehilderRE, forum);
.replace(newsPlaceholderRE, newsProxy)
.replace(forumPlacehilderRE, forumProxy);
};
/* eslint-disable max-len */

View File

@ -4,8 +4,8 @@ const { createRedirects } = require('./create-redirects');
const testLocations = {
api: 'https://api.example.com',
news: 'https://news.example.com',
forum: 'https://forum.example.com'
newsProxy: 'https://news.example.com',
forumProxy: 'https://forum.example.com'
};
describe('createRedirects', () => {
@ -33,21 +33,21 @@ describe('createRedirects', () => {
expect(hasNewsPlaceholder).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(`${forum}`)).toBe(true);
expect(redirects.includes(`${forumProxy}`)).toBe(true);
});
it('throws when any location is missing', () => {
expect.assertions(3);
const api = 'api';
const news = 'news';
const forum = 'forum';
const newsProxy = 'newsProxy';
const forumProxy = 'forumProxy';
const noApi = { forum, news };
const noNews = { api, forum };
const noForum = { api, news };
const noApi = { forumProxy, newsProxy };
const noNews = { api, forumProxy };
const noForum = { api, newsProxy };
expect(() => createRedirects(noApi)).toThrow();
expect(() => createRedirects(noNews)).toThrow();

View File

@ -13,12 +13,7 @@ const log = debug('fcc:tools:ensure-env');
const { FREECODECAMP_NODE_ENV } = process.env;
const {
apiLocation: api,
forumLocation: forum,
locale,
newsLocation: news
} = env;
const { apiLocation: api, locale, forumProxy, newsProxy } = env;
const apiPath = path.resolve(__dirname, '../../../api-server');
const clientPath = path.resolve(__dirname, '../../../client');
@ -26,7 +21,7 @@ const clientStaticPath = path.resolve(clientPath, 'static');
const globalConfigPath = path.resolve(__dirname, '../../../config');
if (FREECODECAMP_NODE_ENV === 'production') {
const redirects = createRedirects({ api, news, forum });
const redirects = createRedirects({ api, newsProxy, forumProxy });
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
if (err) {
log('Error');