fix(updates): Fix learn -> server communication
parent
4eb364f919
commit
3da2a3eea9
|
@ -7,10 +7,10 @@ module.exports = {
|
|||
title: 'freeCodeCamp',
|
||||
siteUrl: 'https://www.freecodecamp.org'
|
||||
},
|
||||
// proxy: {
|
||||
// prefix: '/internal',
|
||||
// url: 'http://localhost:3000'
|
||||
// },
|
||||
proxy: {
|
||||
prefix: '/internal',
|
||||
url: 'http://localhost:3000'
|
||||
},
|
||||
plugins: [
|
||||
'gatsby-plugin-react-helmet',
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ import isEmail from 'validator/lib/isEmail';
|
|||
|
||||
import CardForm from './CardForm';
|
||||
import { injectStripe } from 'react-stripe-elements';
|
||||
import { postJSON$ } from '../../../templates/Challenges/utils/ajax-stream';
|
||||
import postUpdate$ from '../../../templates/Challenges/utils/postUpdate$';
|
||||
|
||||
const propTypes = {
|
||||
email: PropTypes.string,
|
||||
|
@ -102,7 +102,7 @@ class DonateForm extends PureComponent {
|
|||
processing: true
|
||||
}
|
||||
}));
|
||||
return postJSON$('/external/donate/charge-stripe', {
|
||||
return postUpdate$('/donate/charge-stripe', {
|
||||
token,
|
||||
amount
|
||||
}).subscribe(
|
||||
|
|
|
@ -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());
|
||||
// });
|
||||
// }
|
|
@ -4,26 +4,19 @@ import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
|
|||
import createSagaMiddleware from 'redux-saga';
|
||||
import { createEpicMiddleware } from 'redux-observable';
|
||||
|
||||
import servicesCreator from './createServices';
|
||||
import { _csrf } from './cookieValues';
|
||||
|
||||
import rootEpic from './rootEpic';
|
||||
import rootReducer from './rootReducer';
|
||||
import rootSaga from './rootSaga';
|
||||
import { isBrowser } from '../../utils';
|
||||
|
||||
const serviceOptions = {
|
||||
context: _csrf ? { _csrf } : {},
|
||||
xhrPath: '/external/services',
|
||||
xhrTimeout: 15000
|
||||
};
|
||||
const clientSide = isBrowser();
|
||||
|
||||
const sagaMiddleware = createSagaMiddleware();
|
||||
const epicMiddleware = createEpicMiddleware({
|
||||
dependencies: {
|
||||
window: typeof window !== 'undefined' ? window : {},
|
||||
location: typeof window !== 'undefined' ? window.location : {},
|
||||
document: typeof window !== 'undefined' ? document : {},
|
||||
services: servicesCreator(serviceOptions)
|
||||
window: clientSide ? window : {},
|
||||
location: clientSide ? window.location : {},
|
||||
document: clientSide ? document : {}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ function submitModern(type, state) {
|
|||
files
|
||||
};
|
||||
const update = {
|
||||
endpoint: '/external/modern-challenge-completed',
|
||||
endpoint: '/modern-challenge-completed',
|
||||
payload: challengeInfo
|
||||
};
|
||||
return postChallenge(update, username);
|
||||
|
@ -90,7 +90,7 @@ function submitProject(type, state) {
|
|||
}
|
||||
|
||||
const update = {
|
||||
endpoint: '/external/project-completed',
|
||||
endpoint: '/project-completed',
|
||||
payload: challengeInfo
|
||||
};
|
||||
return postChallenge(update, username).pipe(
|
||||
|
@ -110,7 +110,7 @@ function submitBackendChallenge(type, state) {
|
|||
const challengeInfo = { id, solution };
|
||||
|
||||
const update = {
|
||||
endpoint: '/external/backend-challenge-completed',
|
||||
endpoint: '/backend-challenge-completed',
|
||||
payload: challengeInfo
|
||||
};
|
||||
return postChallenge(update, username);
|
||||
|
|
|
@ -18,7 +18,7 @@ function currentChallengeEpic(action$, state$) {
|
|||
filter(({ payload }) => payload !== currentChallengeIdSelector(state$.value)),
|
||||
switchMap(({ payload }) => {
|
||||
const update = {
|
||||
endpoint: '/external/update-my-current-challenge',
|
||||
endpoint: '/update-my-current-challenge',
|
||||
payload: {
|
||||
currentChallengeId: payload
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { postJSON$ } from './ajax-stream';
|
||||
import { from } from 'rxjs';
|
||||
import { post } from '../../../utils/ajax';
|
||||
|
||||
export default function postUpdate$({ endpoint, payload }) {
|
||||
return postJSON$(endpoint, payload);
|
||||
return from(post(endpoint, payload));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ function get(path) {
|
|||
return axios.get(`${base}${path}`);
|
||||
}
|
||||
|
||||
function post(path, body) {
|
||||
export function post(path, body) {
|
||||
return axios.post(`${base}${path}`, body);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue