all files / modules/utils/ createProxy.js

100% Statements 10/10
50% Branches 1/2
100% Functions 2/2
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                  
const Location = require("../Location");
const sendRequest = require("./sendRequest");
const R = require("ramda");
 
/**
 * A proxy is a function that is used to forward a request to
 * a different location and return the response.
 *
 * This function is part of the low-level API and can generally be
 * used more conveniently through the mach.proxy middleware.
 */
function createProxy(location) {
    Eif (!R.is(Location, location)) {
        location = new Location(location);
    }
 
    return function (conn) {
    // Only concat the path from the connection so the protocol,
    // auth, and host from the original location are preserved.
        conn.proxyLocation = location.concat(conn.path);
 
        return sendRequest(conn, conn.proxyLocation);
    };
}
 
module.exports = createProxy;