Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import axios from 'axios';
//import axios from 'axios';
import {
fetchUsers, postToken,
postBlog, getBlogs, getBlog,
} from '../api/fetchUsers';

import { FETCH_USER, FETCH_BLOGS, FETCH_BLOG } from './types';

export const fetchUser = () => async dispatch => {
const res = await axios.get('/api/current_user');
const { data } = fetchUsers();

dispatch({ type: FETCH_USER, payload: res.data });
dispatch({ type: FETCH_USER, payload: data });
};

export const handleToken = token => async dispatch => {
const res = await axios.post('/api/stripe', token);
const {data} = await postToken(token);

dispatch({ type: FETCH_USER, payload: res.data });
dispatch({ type: FETCH_USER, payload: data });
};

export const submitBlog = (values, history) => async dispatch => {
const res = await axios.post('/api/blogs', values);
const {data} = await postBlog(values);

history.push('/blogs');
dispatch({ type: FETCH_BLOG, payload: res.data });
dispatch({ type: FETCH_BLOG, payload: data });
};

export const fetchBlogs = () => async dispatch => {
const res = await axios.get('/api/blogs');
const {data} = await getBlogs();

dispatch({ type: FETCH_BLOGS, payload: res.data });
dispatch({ type: FETCH_BLOGS, payload: data });
};

export const fetchBlog = id => async dispatch => {
const res = await axios.get(`/api/blogs/${id}`);
//const res = await axios.get(`/api/blogs/${id}`);
const {data} = await getBlog(id);

dispatch({ type: FETCH_BLOG, payload: res.data });
dispatch({ type: FETCH_BLOG, payload: data });
};
37 changes: 37 additions & 0 deletions client/src/api/fetchUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import axios from 'axios';

export const fetchUsers = async () =>{

return await axios.get('/api/current_user');

};


export const postToken = async (token) => {
const res = await axios.post('/api/stripe', token);
return res;
};


export const postBlog = async(values) =>{

return await axios.post('/api/blogs', values);
};


export const getBlog = async (id) => {

return await axios.get(`/api/blog/${id}`);

}



export const getBlogs = async (id) => {

return await axios.get(`/api/blogs`);

}



3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ mongoose.connect(keys.mongoURI, { useMongoClient: true });
const app = express();

app.use(bodyParser.json());

app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [keys.cookieKey]
})
);

app.use(passport.initialize());
app.use(passport.session());

Expand All @@ -37,6 +39,7 @@ if (['production'].includes(process.env.NODE_ENV)) {
}

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
console.log(`Listening on port`, PORT);
});