Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chizpon's avatar

Axios CORS

I'm trying to reach from vue to an API (lichess.org's APIs) through axios (from localhost, xampp + apache), but CORS is not having any of it. Is there a way

I've tried this and many variations of it.

	const axiosInstance = axios.create({
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Content-Type":"application/json",
                "X-Requested-With":"XMLHttpRequest",
            }
        });

        axiosInstance
            .get('https://lichess.org/api/games/user/' + this.account + '?max=3/', {
                crossDomain: true,
                accepts: "application/json",
                withCredentials: false,
            })
            .then(response => {
                console.log(response)
            })

And also this, just raw

        axios.get('https://lichess.org/api/games/user/' + this.account + '?max=3/')
            .then(response => {
            console.log(response)
        })
0 likes
1 reply
Chizpon's avatar
Chizpon
OP
Best Answer
Level 6

I had to comment

// window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

in the bootstrapp js

and then this worked

    axios.get('https://lichess.org/api/games/user/' + this.account + '?max=3/')
        .then(response => {
        console.log(response)
    })

Please or to participate in this conversation.