NPM HTTP-Proxy + Virtual directory doesn't work

132 Views Asked by At

We are currently using package "HTTP-proxy" (https://www.npmjs.com/package/http-proxy) for proxy server calls, Below is code how we send proxy server calls.

    const proxyRequestOptions = {

        target: hostInfo.protocol + "//" + hostInfo.host + ":" +  hostInfo.port,
        secure: hostInfo.secure,
        xfwd: true,
        changeOrigin: true,
        agent: agent,
    };

    // Delegate to proxy..
    this.proxyServer.web( request, response, proxyRequestOptions );

Now, the above code working with URL http://localhost/login.aspx, where Localhost is domain, login.aspx is page. But when configured site as virtual directory to another site. then, http://localhost/[Virtual_director] doesn't work. means, if we hit the URL http://localhost/[Virtual_director], but proxy server actually calls the http://localhost not http://localhost/[Virtual_director]. here problem is whenever we call the virtual directory site, its parent site is get called.

We have already tried with appending path with host name like below code, while sending http proxy call but that doesn't work.

// Set options to send proxy requests to classic web host

    const proxyRequestOptions = {

        target: hostInfo.protocol + "//" + hostInfo.host + ":" + ( overRidePortNumber || hostInfo.port ) + hostInfo.pathName,
        secure: hostInfo.secure,
        xfwd: true,
        changeOrigin: true,
        agent: agent,
        prependPath: true
    };

    // Delegate to proxy..

    this.proxyServer.web( request, response, proxyRequestOptions );

It would be helpful if any one help me to sort out this issue. Thank you.

By, Sarath Kumar.

0

There are 0 best solutions below