'React - 400 (Bad Request)

import React, {useState} from 'react';
import axios from 'axios';

function App() {
  const [data, setData] = useState(null);
    const onClick = async() => { 
        try{
            const CLIENT_ID = 'anything';
            const SECRET = 'anything';
            
            const response = await axios.get(
            "/api/v1/search/news.json?query=경제",{
                headers:{
                    'X-Naver-Client-Id': CLIENT_ID,
                    'X-Naver-Client-Secret': SECRET
                }
            }
            );
            setData(response.data);
        } catch(e){
            console.log(e);
        }
    }
    
    return(
        <div>
            <div>
                <button onClick={onClick}>불러오기</button>
            </div>
            {data && <textarea rows={7} value={JSON.stringify(data, null, 2)} readOnly={true} />}
        </div>
    )
}

i have a problem with fetching API... To avoid CORS error, I installed 'http-proxy-middleware'.

I don't know if it's because of that, it occured 400 error

I'm using a cloud server for some reason, could this be a problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source