Skip to content

Commit

Permalink
#9 - after server enables cors, client does not need to use proxy in …
Browse files Browse the repository at this point in the history
…package.json and can directly request the server url while axiosing the requests
  • Loading branch information
jianmingtu committed Apr 14, 2021
1 parent 4a4c351 commit 6c8d6aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "client",
"version": "0.1.0",
"private": true,
"proxy": "https://fathomless-lake-61399.herokuapp.com/",
"dependencies": {
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
Expand Down
6 changes: 3 additions & 3 deletions client/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const authHeader = () => { return { Authorization: `Bearer ${localStorage.getIte
export async function getPosts() {
try {
// Send the JWT in the header of the axios requests from the client
const result = await axios.get(`/api/posts`, { headers: authHeader() })
const result = await axios.get(`${BASE_API}/posts`, { headers: authHeader() })
console.log(result)
return result.data
} catch (error) {
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function savePost(data) {

console.log({ ...data, upload_image_file:ret?.location})

await axios.post(`/api/posts`, { ...data, upload_image_file:ret?.location }, { headers: authHeader() })
await axios.post(`${BASE_API}/posts`, { ...data, upload_image_file:ret?.location }, { headers: authHeader() })
} catch (err) {
throw (err.message || JSON.stringify(err))
}
Expand All @@ -74,7 +74,7 @@ export async function getPost({postId}) {

export async function login({username, password}) {
try {
const result = await axios.post('/api/users/login', {username, password})
const result = await axios.post(`${BASE_API}/users/login`,{username, password})
const token = result.data.accessToken
saveToken(token)
return getDecodedToken()
Expand Down

0 comments on commit 6c8d6aa

Please sign in to comment.