I am having problem using http-proxy-middleware
01:54 12 Jan 2021

I have two servers running in my backend, because of that I have to use the http-proxy-middleware package but I am encountering some problems.

This is my code in the frontend which is running on localhost:3000

axios("/api2/login",data)
    .then((res) => {
});

This is my code in the backend which is running on localhost:5001

const { createProxyMiddleware } = require('http-proxy-middleware');

app.use(createProxyMiddleware('/api2', {target: 'http://localhost:5001', changeOrigin: true}))

app.post("/login", (req, res, next) => {
    res.send("Logged In");
});

This code is no working showing this error in the browser's console

GET http://localhost:3000/api2/login 404 (Not Found)
Uncaught (in promise) Error: Request failed with status code 404
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.handleLoad (xhr.js:61)

I am not able to understand where I am going wrong.

node.js reactjs express http-proxy-middleware