Skip to content

Do Not Proxy Request When Custom Router Throws Error #411

@bforbis

Description

@bforbis

I am trying to take complete control of the target routing. I would like the proxied request to be aborted before the client socket is opened if my router was unable to determine a target host. Is this possible to do?

createProxyMiddleware({
  // target is a required parameter
  target: 'do-not-use', 
  router: (req) => {
    try {
      ...
      return target;
    }
    catch (err) {
      req.res.sendStatus(500);
    }
  },
});

The current http-proxy code will still use the original target "do-not-use". I would rather the proxy just abort the request entirely if the router function does not return a target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions