Search code examples
javascriptnode.jsexpresshttp-proxyhttp-proxy-middleware

Difference between passing function and the () => {} in express


What is the difference between these two? Only (1) is working and (2) is stuck in the browser;

(1) app.get('/source*', createProxyMiddleware({ target: serviceProvider}))

(2) app.get('/source*', () => { createProxyMiddleware({ target: serviceProvider}) })


Solution

  • createProxyMiddleware({ target: serviceProvider})
    

    this returns a function that is yet to be excuted with the parameters from express middleware. to make second example to work, you will simply need to excute the returned function as following

    2) app.get('/source*', (req, res, next) => {
      const func = createProxyMiddleware({ target: serviceProvider});
      func(req, res, next);
    })