diff --git a/package.json b/package.json index 0e27f2635..005b70bc8 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ }, "main": "/theme.scss", "dependencies": { - "axios": "^1.4.0", "bulma": "^0.9.4", "bulma-checkradio": "^1.1.1", "bulma-switch": "^2.0.4", diff --git a/src/main.js b/src/main.js index 6ec407320..abb9e2351 100644 --- a/src/main.js +++ b/src/main.js @@ -9,12 +9,38 @@ import Clipboard from 'v-clipboard'; import store from './store/index.js'; import InfiniteLoading from 'vue-infinite-loading'; import VueResource from 'vue-resource'; -import DOMPurify from 'dompurify'; import VueObserveVisibility from 'vue-observe-visibility'; import AsyncComputed from 'vue-async-computed'; var VueScrollTo = require('vue-scrollto'); + +const {fetch: originalFetch} = global; + +let PENDING_REQUESTS = 0; +const MAX_REQUESTS_COUNT = 10; +const INTERVAL_MS = 10; + +global.fetch = async(...args) => { + let [resource, config] = args; + // request interceptor here + if (PENDING_REQUESTS >= MAX_REQUESTS_COUNT) { + return new Promise((resolve) => { + setTimeout(() => { + resolve(global.fetch(...args)); + }, INTERVAL_MS); + }); + } else { + PENDING_REQUESTS++; + const response = await originalFetch(resource, config); + + PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1); + // response interceptor here + return response; + } +}; + + require("cassproject"); global.UUID = require('pure-uuid'); diff --git a/src/store/modules/editor.js b/src/store/modules/editor.js index 2b32fed1a..2f3b8dcbc 100644 --- a/src/store/modules/editor.js +++ b/src/store/modules/editor.js @@ -1,36 +1,8 @@ import Vue from 'vue'; import Vuex from 'vuex'; -import axios from 'axios'; Vue.use(Vuex); -// Rate Limit axios requests -const MAX_REQUESTS_COUNT = 10; -const INTERVAL_MS = 10; -let PENDING_REQUESTS = 0; - -const limitApi = axios.create({}); - -limitApi.interceptors.request.use(function(config) { - return new Promise((resolve, reject) => { - let interval = setInterval(() => { - if (PENDING_REQUESTS < MAX_REQUESTS_COUNT) { - PENDING_REQUESTS++; - clearInterval(interval); - resolve(config); - } - }, INTERVAL_MS); - }); -}); - -limitApi.interceptors.response.use(function(response) { - PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1); - return Promise.resolve(response); -}, function(error) { - PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1); - return Promise.reject(error); -}); - const state = { framework: null, organization: null,