0

my third party axios requests works properly on local mode properly thanks to "http-proxy-middleware", but after i build and deploy it, axios requests gives homepage html as response.

setupProxy.js file

const { createProxyMiddleware } = require("http-proxy-middleware")
const cors=require("cors")
const express = require('express');
const app = express();
module.exports=app=>{
 
    app.use(
        createProxyMiddleware("/api",
        {
            target:"third-party-api-url",
            secure:false,
            changeOrigin:true
        })
    )

ApiFrontend.jsx file

const [apiData,setApiData]=useState("")
  var data = JSON.stringify({
    "MERCHANT": "****",
    "MERCHANT_KEY": "*******************************"
  });
var config = {
    method: 'POST',
    headers: { 
      'Content-Type': 'application/json'
    },
    data : data
  };


  useEffect(()=>{
    axios("/api",config)
    .then(function (response) {
      setApiData(response.data);
    })
    .catch(function (error) {
      console.log(error);
    });
  },[])

i tried node server with express and use;

app.use(cors({ 
  origin: API_URL, 
  credentials: true 
 }));

but it gives the same response

Faruk
  • 9
  • 2

0 Answers0