|
@@ -5,15 +5,17 @@ type ISend = {
|
|
|
path: string,
|
|
|
data?: any,
|
|
|
token: string
|
|
|
+ customHeaders?: Record<string, string>,
|
|
|
}
|
|
|
|
|
|
type IOption = {
|
|
|
method: string,
|
|
|
headers: Record<string, string>,
|
|
|
body: any
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-async function send({ method, path, data, token }: ISend) {
|
|
|
+async function send({ method, path, data, token, customHeaders }: ISend) {
|
|
|
const opts: IOption = { method, headers: {} } as IOption;
|
|
|
|
|
|
if (data) {
|
|
@@ -21,6 +23,11 @@ async function send({ method, path, data, token }: ISend) {
|
|
|
opts.body = JSON.stringify(data);
|
|
|
}
|
|
|
|
|
|
+ if (customHeaders) {
|
|
|
+ console.log(customHeaders);
|
|
|
+ // opts.headers[customHeader.$1]
|
|
|
+ }
|
|
|
+
|
|
|
if (token) {
|
|
|
opts.headers['Authorization'] = `Bearer ${token}`;
|
|
|
}
|
|
@@ -36,18 +43,18 @@ async function send({ method, path, data, token }: ISend) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-export function getRequest(path: string, token: string) {
|
|
|
- return send({ method: 'GET', path, token });
|
|
|
+export function getRequest(path: string, token: string, customHeaders?: Record<string, string>) {
|
|
|
+ return send({ method: 'GET', path, token, customHeaders });
|
|
|
}
|
|
|
|
|
|
-export function delRequest(path: string, token: string) {
|
|
|
- return send({ method: 'DELETE', path, token });
|
|
|
+export function delRequest(path: string, token: string, customHeaders?: Record<string, string>) {
|
|
|
+ return send({ method: 'DELETE', path, token, customHeaders });
|
|
|
}
|
|
|
|
|
|
-export function postRequest(path: string, data: any, token: string) {
|
|
|
- return send({ method: 'POST', path, data, token });
|
|
|
+export function postRequest(path: string, data: any, token: string, customHeaders?: Record<string, string>) {
|
|
|
+ return send({ method: 'POST', path, data, token, customHeaders });
|
|
|
}
|
|
|
|
|
|
-export function putRequest(path: string, data: any, token: string) {
|
|
|
- return send({ method: 'PUT', path, data, token });
|
|
|
+export function putRequest(path: string, data: any, token: string, customHeaders?: Record<string, string>) {
|
|
|
+ return send({ method: 'PUT', path, data, token, customHeaders });
|
|
|
}
|