fix(api): remove redirects from api
They should be handled either by nginx or by the client. Turned out a lot of code, including the path migration, existed to support them. Hence the large number of removals
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
4a45b5ac1c
commit
1ad5f756e0
@ -2,41 +2,10 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
const log = debug('fcc:tools:ensure-env');
|
||||
|
||||
const env = require('../../../config/env');
|
||||
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('../seed/createPathMigrationMap');
|
||||
|
||||
const apiPath = path.resolve(__dirname, '../../../api-server');
|
||||
const clientPath = path.resolve(__dirname, '../../../client');
|
||||
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
||||
|
||||
const { FREECODECAMP_NODE_ENV } = process.env;
|
||||
const { locale } = env;
|
||||
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
fs.access(migrationMapPath, err => {
|
||||
if (err && FREECODECAMP_NODE_ENV !== 'production') {
|
||||
log('creating pathMigration');
|
||||
return fs.writeFileSync(migrationMapPath, '{}');
|
||||
}
|
||||
if (FREECODECAMP_NODE_ENV === 'production') {
|
||||
return getChallengesForLang(locale)
|
||||
.then(createPathMigrationMap)
|
||||
.then(map => {
|
||||
fs.writeFileSync(migrationMapPath, JSON.stringify(map));
|
||||
log('pathMigration has been written');
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
// eslint-disable-next-line
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
log('pathMigration present');
|
||||
return null;
|
||||
});
|
||||
|
||||
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
|
||||
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));
|
||||
|
@ -1,30 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('../seed/createPathMigrationMap');
|
||||
|
||||
const log = debug('fcc:tools:ensure-env');
|
||||
|
||||
log.enabled = true;
|
||||
|
||||
const apiPath = path.resolve(__dirname, '../../api-server');
|
||||
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
|
||||
// The migrationMap is to try and resolve pre-learn challenge urls to
|
||||
// current challenge urls
|
||||
// defaulting to english as there were no other languages available
|
||||
// that would require this mapping
|
||||
getChallengesForLang('english')
|
||||
.then(createPathMigrationMap)
|
||||
.then(map => {
|
||||
fs.writeFileSync(migrationMapPath, JSON.stringify(map));
|
||||
log('pathMigration has been written');
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
// eslint-disable-next-line
|
||||
process.exit(1);
|
||||
});
|
@ -1,17 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`createPathMigrationMap output snapshot 1`] = `
|
||||
Object {
|
||||
"challenge-eight": "/learn/super-block-a/block-two/challenge-eight",
|
||||
"challenge-eleven": "/learn/super-block-b/block-one/challenge-eleven",
|
||||
"challenge-five": "/learn/super-block-a/block-two/challenge-five",
|
||||
"challenge-four": "/learn/super-block-a/block-one/challenge-four",
|
||||
"challenge-one": "/learn/super-block-a/block-one/challenge-one",
|
||||
"challenge-seven": "/learn/super-block-a/block-two/challenge-seven",
|
||||
"challenge-six": "/learn/super-block-a/block-two/challenge-six",
|
||||
"challenge-ten": "/learn/super-block-b/block-one/challenge-ten",
|
||||
"challenge-three": "/learn/super-block-a/block-one/challenge-three",
|
||||
"challenge-twelve": "/learn/super-block-b/block-one/challenge-twelve",
|
||||
"challenge-two": "/learn/super-block-a/block-one/challenge-two",
|
||||
}
|
||||
`;
|
@ -1,27 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
|
||||
const debug = require('debug');
|
||||
|
||||
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('./createPathMigrationMap');
|
||||
|
||||
const log = debug('fcc:tools:seedChallenges');
|
||||
const { LOCALE: lang = 'english' } = process.env;
|
||||
|
||||
getChallengesForLang(lang).then(curriculum => {
|
||||
log('generating path migration map');
|
||||
const pathMap = createPathMigrationMap(curriculum);
|
||||
const outputDir = path.resolve(
|
||||
__dirname,
|
||||
'../../../api-server/server/resources/pathMigration.json'
|
||||
);
|
||||
fs.writeFile(outputDir, JSON.stringify(pathMap), err => {
|
||||
if (err) {
|
||||
console.error('failed to save pathMigration');
|
||||
console.error(err);
|
||||
} else {
|
||||
log('path migration map generated');
|
||||
}
|
||||
});
|
||||
});
|
@ -1,25 +0,0 @@
|
||||
const { flatten } = require('lodash');
|
||||
|
||||
const { dasherize } = require('../../../utils/slugs');
|
||||
|
||||
function createPathMigrationMap(curriculum) {
|
||||
return Object.keys(curriculum)
|
||||
.map(key => curriculum[key].blocks)
|
||||
.reduce((challenges, current) => {
|
||||
const superChallenges = Object.keys(current).map(
|
||||
key => current[key].challenges
|
||||
);
|
||||
return challenges.concat(flatten(superChallenges));
|
||||
}, [])
|
||||
.filter(({ isPrivate }) => !isPrivate)
|
||||
.reduce((map, challenge) => {
|
||||
const { title, block, superBlock } = challenge;
|
||||
const dashedTitle = dasherize(title);
|
||||
map[dashedTitle] = `/learn/${dasherize(superBlock)}/${dasherize(
|
||||
block
|
||||
)}/${dashedTitle}`;
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
exports.createPathMigrationMap = createPathMigrationMap;
|
@ -1,36 +0,0 @@
|
||||
/* global describe expect */
|
||||
const { isPlainObject } = require('lodash');
|
||||
|
||||
const { createPathMigrationMap } = require('./createPathMigrationMap');
|
||||
const mockCurriculum = require('./__mocks__/curriculum.json');
|
||||
|
||||
describe('createPathMigrationMap', () => {
|
||||
const pathMap = createPathMigrationMap(mockCurriculum);
|
||||
|
||||
it('is a function', () => {
|
||||
expect(typeof createPathMigrationMap).toEqual('function');
|
||||
});
|
||||
|
||||
it('returns an object', () => {
|
||||
expect(isPlainObject(pathMap)).toBe(true);
|
||||
});
|
||||
|
||||
it('maps a challenge title to the correct uri slug', () => {
|
||||
expect.assertions(3);
|
||||
const slugOne = '/learn/super-block-b/block-one/challenge-ten';
|
||||
const slugTwo = '/learn/super-block-a/block-two/challenge-five';
|
||||
const slugThree = '/learn/super-block-a/block-one/challenge-three';
|
||||
|
||||
expect(pathMap['challenge-ten']).toEqual(slugOne);
|
||||
expect(pathMap['challenge-five']).toEqual(slugTwo);
|
||||
expect(pathMap['challenge-three']).toEqual(slugThree);
|
||||
});
|
||||
|
||||
it('does not add uri migrations for private challenges', () => {
|
||||
expect(pathMap['challenge-nine']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('output snapshot', () => {
|
||||
expect(createPathMigrationMap(mockCurriculum)).toMatchSnapshot();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user