From 6c8d6aa6db7985bcd2081d8f9f6a1b9c0068b4ce Mon Sep 17 00:00:00 2001 From: jianmingtu Date: Wed, 14 Apr 2021 07:22:16 -0700 Subject: [PATCH] #9 - after server enables cors, client does not need to use proxy in package.json and can directly request the server url while axiosing the requests --- client/package.json | 1 - client/src/network.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/client/package.json b/client/package.json index 539f5f1..0e659ad 100644 --- a/client/package.json +++ b/client/package.json @@ -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", diff --git a/client/src/network.js b/client/src/network.js index c2c5f1d..b629bd4 100644 --- a/client/src/network.js +++ b/client/src/network.js @@ -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) { @@ -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)) } @@ -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()