1

We have an Angular 12 app with a proxy.conf.js file used with ng serve --proxy-config proxy.conf.js in order to proxy the API calls to the local back-end server. While we're working on new features for which the back-end is not yet ready, I would like to send the yet-not-implemented API calls to another local server which serves mock data. The problem is, the target URL for both is the same, the only difference is a URL query parameter. The normal proxy.conf.js file looks like this:

const PROXY_CONFIG = {
    "/api": {
        "target": "http://127.0.0.1:8082",
        "secure": false
    }
};
module.exports = PROXY_CONFIG;

To add the mock server, I tried something like this:

const PROXY_CONFIG = {
    "/api": {
        "target": "http://127.0.0.1:8082",
        "secure": false,
        bypass: function (req, res) {
            if (/\?myparam=somevalue$/.test(req.originalUrl)) {
                return res.redirect(200, 'http://127.0.0.1:3000/'));
            }
        }
    }
};

I tried many variations on this, with different parameters, but none was successful. What am I missing?

AsGoodAsItGets
  • 2,886
  • 34
  • 49

0 Answers0