I am using axios in reactjs which is running on port 3000 & Rails 6 API application is running in 3001.
I hit for /authenticate POST API & checked in the browser network tab for xhr tab where I found status as (cancelled) and no response or error.
On rails log,
Started POST "/api/v1/authenticate" for ::1 at 2020-09-04 09:56:49 +0530
Processing by Api::V1::AuthenticationController#authenticate as HTML
Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "authentication"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}
Please suggest what I am doing wrong here
My axios call is like below,
const response = await axios({
URL: "http://localhost:3001/api/v1/authenticate",
method: "POST",
data: {"email":"[email protected]","password":"123123123"},
headers: { 'Content-Type': 'application/json' }
});
I followed reference but did not work
src/setupProxy.js
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/api/v1',
createProxyMiddleware({
target: 'http://localhost:3001/',
changeOrigin: true,
})
);
};
API seems right as following return token in response json data,
curl -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","password":"123123123"}' http://localhost:3001/api/v1/authenticate