Wrap axiosInstance inside a wrapper to contain the warnings

This commit is contained in:
Simone Taeggi 2022-11-11 17:54:11 +01:00
parent 4a211a50d0
commit 68fee16bd2
8 changed files with 119 additions and 39 deletions

View File

@ -1,10 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -37,4 +33,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -3,10 +3,6 @@ import { auth } from '@strapi/helper-plugin';
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from fetchClient // TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from fetchClient
import pluginId from '../pluginId'; import pluginId from '../pluginId';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: `${process.env.STRAPI_ADMIN_BACKEND_URL}/${pluginId}`, baseURL: `${process.env.STRAPI_ADMIN_BACKEND_URL}/${pluginId}`,
}); });
@ -39,4 +35,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -1,10 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -37,4 +33,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -1,10 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });

View File

@ -5,10 +5,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -41,4 +37,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -5,10 +5,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -41,4 +37,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -1,10 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -37,4 +33,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;

View File

@ -1,10 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { auth } from '@strapi/helper-plugin'; import { auth } from '@strapi/helper-plugin';
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
const instance = axios.create({ const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL, baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
}); });
@ -37,4 +33,20 @@ instance.interceptors.response.use(
} }
); );
export default instance; const wrapper = {};
['request', 'get', 'head', 'delete', 'options', 'post', 'put', 'patch', 'getUri'].forEach(
(methodName) => {
wrapper[methodName] = (...args) => {
console.log(
'Deprecation warning: Usage of "axiosInstance" utility is deprecated and will be removed in the next major release. Instead, use the useFetchClient() hook, which is exported from the helper-plugin: { useFetchClient } from "@strapi/helper-plugin"'
);
return instance[methodName](...args);
};
return wrapper;
}
);
export default wrapper;