kuitos / axios-extensions

🍱 axios extensions lib, including throttle, cache, retry features etc...
MIT License
831 stars 49 forks source link

Cache-Control header issue #5

Closed looterz closed 6 years ago

looterz commented 6 years ago

I've ran into this error when specifying the headers option to include 'Cache-Control no-cache' as specified in the readme.

Failed to load resource: the server responded with a status of 404 (Not Found)
Response for preflight has invalid HTTP status code 404

The API server in question is https://api.scryfall.com , I tried some suggested workarounds online like specifying the following extra headers,

headers: { 
    'Cache-Control': 'no-cache',
    'Content-type': 'application/json',
    'Access-Control-Allow-Methods': 'GET, POST',
    'Access-Control-Allow-Headers': 'Content-type, Accept'
}

but the server still rejects requests. For now im simply not specifying Cache-Control in the HTTP client's headers, any idea how I could fix this issue?

Here is a test script you can use to duplicate the issue,

import axios from 'axios'
import { cacheAdapterEnhancer } from 'axios-extensions'

const api = axios.create({
    baseURL: 'https://api.scryfall.com/',
    headers: {'Cache-Control': 'no-cache'},
    adapter: cacheAdapterEnhancer(axios.defaults.adapter, true)
})

export async function searchCards(query) {
    return new Promise((resolve, reject) => {
        api.get(`cards/search?q=${query}&pretty=true`).then((res) => {
            resolve(res.data.data)
        }).catch((e) => {
            reject(e)
        })
    })
}

let cards
try {
    cards = await searchCards('wizard')
    console.log(cards)
} catch(e) {
    console.log(e)
}
looterz commented 6 years ago

Disregard, seems to be an issue with developing locally & CORS.