fix(updates): Fix learn -> server communication

This commit is contained in:
Bouncey
2018-09-30 12:19:37 +01:00
committed by Stuart Taylor
parent 4eb364f919
commit 3da2a3eea9
8 changed files with 19 additions and 66 deletions

View File

@ -7,10 +7,10 @@ module.exports = {
title: 'freeCodeCamp', title: 'freeCodeCamp',
siteUrl: 'https://www.freecodecamp.org' siteUrl: 'https://www.freecodecamp.org'
}, },
// proxy: { proxy: {
// prefix: '/internal', prefix: '/internal',
// url: 'http://localhost:3000' url: 'http://localhost:3000'
// }, },
plugins: [ plugins: [
'gatsby-plugin-react-helmet', 'gatsby-plugin-react-helmet',
{ {

View File

@ -4,7 +4,7 @@ import isEmail from 'validator/lib/isEmail';
import CardForm from './CardForm'; import CardForm from './CardForm';
import { injectStripe } from 'react-stripe-elements'; import { injectStripe } from 'react-stripe-elements';
import { postJSON$ } from '../../../templates/Challenges/utils/ajax-stream'; import postUpdate$ from '../../../templates/Challenges/utils/postUpdate$';
const propTypes = { const propTypes = {
email: PropTypes.string, email: PropTypes.string,
@ -102,7 +102,7 @@ class DonateForm extends PureComponent {
processing: true processing: true
} }
})); }));
return postJSON$('/external/donate/charge-stripe', { return postUpdate$('/donate/charge-stripe', {
token, token,
amount amount
}).subscribe( }).subscribe(

View File

@ -1,41 +0,0 @@
import { Observable } from 'rxjs';
import Fetchr from 'fetchr';
function callbackObserver(observer) {
return (err, res) => {
if (err) {
return observer.error(err);
}
observer.next(res);
return observer.complete();
};
}
export default function servicesCreator(options) {
const services = new Fetchr(options);
return {
readService$({ service: resource, params = {} }) {
return Observable.create(observer =>
services
.read(resource)
.params(params)
.end(callbackObserver(observer))
);
}
};
}
// createService$({ service: resource, params, body, config }) {
// return Observable.create(observer => {
// services.create(
// resource,
// params,
// body,
// config,
// callbackObserver(observer)
// );
// return Subscription.create(() => observer.dispose());
// });
// }

View File

@ -4,26 +4,19 @@ import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import { createEpicMiddleware } from 'redux-observable'; import { createEpicMiddleware } from 'redux-observable';
import servicesCreator from './createServices';
import { _csrf } from './cookieValues';
import rootEpic from './rootEpic'; import rootEpic from './rootEpic';
import rootReducer from './rootReducer'; import rootReducer from './rootReducer';
import rootSaga from './rootSaga'; import rootSaga from './rootSaga';
import { isBrowser } from '../../utils';
const serviceOptions = { const clientSide = isBrowser();
context: _csrf ? { _csrf } : {},
xhrPath: '/external/services',
xhrTimeout: 15000
};
const sagaMiddleware = createSagaMiddleware(); const sagaMiddleware = createSagaMiddleware();
const epicMiddleware = createEpicMiddleware({ const epicMiddleware = createEpicMiddleware({
dependencies: { dependencies: {
window: typeof window !== 'undefined' ? window : {}, window: clientSide ? window : {},
location: typeof window !== 'undefined' ? window.location : {}, location: clientSide ? window.location : {},
document: typeof window !== 'undefined' ? document : {}, document: clientSide ? document : {}
services: servicesCreator(serviceOptions)
} }
}); });

View File

@ -67,7 +67,7 @@ function submitModern(type, state) {
files files
}; };
const update = { const update = {
endpoint: '/external/modern-challenge-completed', endpoint: '/modern-challenge-completed',
payload: challengeInfo payload: challengeInfo
}; };
return postChallenge(update, username); return postChallenge(update, username);
@ -90,7 +90,7 @@ function submitProject(type, state) {
} }
const update = { const update = {
endpoint: '/external/project-completed', endpoint: '/project-completed',
payload: challengeInfo payload: challengeInfo
}; };
return postChallenge(update, username).pipe( return postChallenge(update, username).pipe(
@ -110,7 +110,7 @@ function submitBackendChallenge(type, state) {
const challengeInfo = { id, solution }; const challengeInfo = { id, solution };
const update = { const update = {
endpoint: '/external/backend-challenge-completed', endpoint: '/backend-challenge-completed',
payload: challengeInfo payload: challengeInfo
}; };
return postChallenge(update, username); return postChallenge(update, username);

View File

@ -18,7 +18,7 @@ function currentChallengeEpic(action$, state$) {
filter(({ payload }) => payload !== currentChallengeIdSelector(state$.value)), filter(({ payload }) => payload !== currentChallengeIdSelector(state$.value)),
switchMap(({ payload }) => { switchMap(({ payload }) => {
const update = { const update = {
endpoint: '/external/update-my-current-challenge', endpoint: '/update-my-current-challenge',
payload: { payload: {
currentChallengeId: payload currentChallengeId: payload
} }

View File

@ -1,5 +1,6 @@
import { postJSON$ } from './ajax-stream'; import { from } from 'rxjs';
import { post } from '../../../utils/ajax';
export default function postUpdate$({ endpoint, payload }) { export default function postUpdate$({ endpoint, payload }) {
return postJSON$(endpoint, payload); return from(post(endpoint, payload));
} }

View File

@ -6,7 +6,7 @@ function get(path) {
return axios.get(`${base}${path}`); return axios.get(`${base}${path}`);
} }
function post(path, body) { export function post(path, body) {
return axios.post(`${base}${path}`, body); return axios.post(`${base}${path}`, body);
} }