1

This is my middleware file known as setupProxy.js.

I have my express server running on port 5000, I also have my app using '/todos';

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

module.exports = function(app) {
    console.log('Proxy setup');
  app.use(
    '/testing', 
    createProxyMiddleware({
        target: 'http://localhost:5000/todos',
        changeOrigin: true,
    })
  );
};

I do an api call

    await axios.get('/testing/home', {validateStatus: false})
            .then(async (response) => {

             }

This throws an error

GET http://localhost:5000/testing/home 404 (Not Found)

Why is my proxy not pushing /testing/home to localhost:5000/todos/home?

I have the setupProxy.js file in the src folder, the package json is separated from my servers package.json file. Am I supposed to proxy from the backend instead of the front-end or something? I can get all normal requests for /todos/* from my front-end so it just seems like the proxy isnt working at all.

Shooting Stars
  • 755
  • 1
  • 9
  • 20

0 Answers0