Creating an MSA involves utilizing both a front server and backend server. In this case, the frontend calls the api/route structure file api, which then calls the backend api using axios. However, I keep encountering a red line error mark when trying to use return new Response(callAxios())
, most likely due to the inability to confirm the type as JSON or String.
https://i.sstatic.net/RcnAz.png
import axios from "axios"
export async function GET(request: Request) {
return new Response(callAxios())
}
async function callAxios(){
await axios.get('http://localhost:8080/firstCall', {
params: { // query string
title: 'NEXT JS'
},
headers: {
'X-Api-Key': 'my-api-key'
},
}).then(res => {
console.log(res.data)
return res.data
})
}
I am still able to retrieve JSON data despite the error mark, but how can I eliminate it? Note that I am new to TypeScript and have just started learning today.
Can you help me resolve the error mark and ensure the correct acceptance of data types?