-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop-FE' into fix/#472-permission
- Loading branch information
Showing
11 changed files
with
343 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
// const API_URL = | ||
// process.env.NODE_ENV === 'production' | ||
// ? process.env.REACT_APP_API_DEFAULT_PROD | ||
// : process.env.REACT_APP_API_DEFAULT_DEV; | ||
|
||
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : DEFAULT_PROD_URL | ||
|
||
import { DEFAULT_PROD_URL } from '../constants'; | ||
import { ContentTypeType } from '../types/Api'; | ||
import withTokenRefresh from './utils'; | ||
|
||
interface Headers { | ||
'content-type': string; | ||
[key: string]: string; | ||
} | ||
|
||
export const deleteApi = async (url: string, contentType?: ContentTypeType) => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
const headers: Headers = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'DELETE', | ||
headers, | ||
return await withTokenRefresh(async () => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
const headers: Headers = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'DELETE', | ||
headers, | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] DELETE ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] DELETE ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,58 @@ | ||
import { DEFAULT_PROD_URL } from '../constants'; | ||
import { ContentTypeType } from '../types/Api'; | ||
|
||
interface Headers { | ||
'content-type': string; | ||
[key: string]: string; | ||
} | ||
|
||
interface HeadersForm { | ||
[key: string]: string; | ||
} | ||
import withTokenRefresh from './utils'; | ||
|
||
export const postApi = async ( | ||
url: string, | ||
payload: {} | FormData, | ||
contentType?: ContentTypeType, | ||
) => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
return await withTokenRefresh(async () => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
|
||
if (payload instanceof FormData) { | ||
const headers: any = {}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'POST', | ||
headers, | ||
body: payload, | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] POST ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
if (payload instanceof FormData) { | ||
const headers: HeadersForm = {}; | ||
const headers: any = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'POST', | ||
headers, | ||
body: payload, | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] POST ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
const headers: Headers = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] POST ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
import { DEFAULT_PROD_URL } from '../constants'; | ||
import { ContentTypeType } from '../types/Api'; | ||
interface Headers { | ||
'content-type': string; | ||
[key: string]: string; | ||
} | ||
import withTokenRefresh from './utils'; | ||
|
||
export const putApi = async ( | ||
url: string, | ||
data: {}, | ||
contentType?: ContentTypeType, | ||
) => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
const headers: Headers = { | ||
'content-type': 'application/json', | ||
}; | ||
return await withTokenRefresh(async () => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
const headers: any = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'PUT', | ||
headers, | ||
body: JSON.stringify(data), | ||
}); | ||
const response = await fetch(apiUrl, { | ||
method: 'PUT', | ||
headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] PUT ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
if (response.status >= 400) { | ||
throw new Error('[SERVER] PUT ์์ฒญ์ ์คํจํ์ต๋๋ค.'); | ||
} | ||
|
||
return response; | ||
return response; | ||
}); | ||
}; |
Oops, something went wrong.