Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(key, config) {
// extract any non-axios-specific config (like cache mode, mock mode ...)
const {
isCacheEnabled,
mocks,
makeMockedClient,
preprocessMocking,
...axiosConfig
} = makeConfig(key, config);
if (!instance[key]) {
instance[key] = decorate(key, this);
if (isCacheEnabled) {
this.cache = setupCache({ maxAge: 15 * 60 * 1000 });
axiosConfig.adapter = this.cache.adapter;
if (process.env.NODE_ENV === "development") {
console.info(`[ApiManager](${key}) Cache is enabled`, this.cache);
}
}
if (mocks) {
console.warn(
`[ApiManager](${key}) Mocking API. Requests will be intercepted and served. The files containing the mocks are in src/services/mocks. To generate those files, run: npm run record-http-mocks.`
);
console.warn(
`[ApiManager](${key}) Unmocked requests will pass through and will be logged.`
);
this.client = makeMockedClient(axiosConfig, mocks, {
preprocessMocking
});
} else {
import axios from 'axios'
import { setupCache } from 'axios-cache-adapter'
const cache = setupCache({
maxAge: 3 * 60 * 1000 // Three minutes
})
const instance = axios.create({
adapter: cache.adapter,
baseURL: 'https://gcq2gnybeb.execute-api.us-east-1.amazonaws.com/dev'
})
export const fetchJobsByCategory = category =>
instance.get(`/github/jobs/${category}`).then(res => res.data)
export const fetchJob = (ownerName, issueNumber) =>
instance
.get(`/github/jobs/repository/${ownerName}/${issueNumber}`)
.then(res => res.data)
import axios from 'axios';
import envConfig from '../../config/env-config';
import { setupCache } from 'axios-cache-adapter';
let apiUrl;
if (process.browser) {
// in client side, we don't have dotEnv config, so we have to set apiUrl
// in window object and get it here
apiUrl = window.apiUrl;
} else {
apiUrl = envConfig.app.apiUrl;
}
// Create `axios-cache-adapter` instance
const cache = setupCache({ maxAge: 15 * 60 * 100, exclude: { query: false } });
const noCache = setupCache({ maxAge: 0 });
const createAxiosInstance = (path, disableCache) => {
return axios.create({
baseURL: apiUrl + path,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
timeout: 9000,
adapter: disableCache ? noCache.adapter : cache.adapter
});
};
export async function fetchApi(path, pathParam, query = null, disableCache = false) {
// always disable cache if request doesn't come from client-side
import axios from 'axios';
import envConfig from '../../config/env-config';
import { setupCache } from 'axios-cache-adapter';
let apiUrl;
if (process.browser) {
// in client side, we don't have dotEnv config, so we have to set apiUrl
// in window object and get it here
apiUrl = window.apiUrl;
} else {
apiUrl = envConfig.app.apiUrl;
}
// Create `axios-cache-adapter` instance
const cache = setupCache({ maxAge: 15 * 60 * 100, exclude: { query: false } });
const noCache = setupCache({ maxAge: 0 });
const createAxiosInstance = (path, disableCache) => {
return axios.create({
baseURL: apiUrl + path,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
timeout: 9000,
adapter: disableCache ? noCache.adapter : cache.adapter
});
};
export async function fetchApi(path, pathParam, query = null, disableCache = false) {
// always disable cache if request doesn't come from client-side
if (!process.browser) disableCache = true;
generateCacheAdapter() {
this.cacheConfig.store = this.cacheStore
this.cacheConfig.key = this.generateCacheKey
this.cacheConfig.invalidate = this.shouldInvalidate
let cache = setupCache( this.cacheConfig )
return cache.adapter
}
}
import Promise from 'promise'
import axios from 'axios'
import { setupCache } from 'axios-cache-adapter'
import qs from 'qs'
const { apiRoot, nonce } = FL_ASSISTANT_CONFIG
/**
* Cache adapter for axios requests.
*
* @type {Object}
*/
const cache = setupCache( {
debug: false,
maxAge: 15 * 60 * 1000,
exclude: {
query: false,
},
key: ( req ) => {
let key = req.url + qs.stringify( req.params, { addQueryPrefix: true } )
if ( req.cacheKey ) {
return `fl-cache-${ req.cacheKey }-${ key }`
}
return key
},
invalidate: ( config, req ) => {
const method = req.method.toLowerCase()
if ( req.cacheKey && 'get' !== method ) {
config.store.iterate( ( data, key ) => {