MCPcopy
hub / github.com/rendrjs/rendr / apiProxy

Function apiProxy

server/middleware/apiProxy.js:15–43  ·  view source on GitHub ↗
(dataAdapter)

Source from the content-addressed store, hash-verified

13module.exports = apiProxy;
14
15function apiProxy(dataAdapter) {
16 return function(req, res, next) {
17 var api;
18
19 api = _.pick(req, 'query', 'method', 'body');
20
21 api.path = apiProxy.getApiPath(req.path);
22 api.api = apiProxy.getApiName(req.path);
23 api.headers = {
24 'x-forwarded-for': apiProxy.getXForwardedForHeader(req.headers, req.ip)
25 };
26
27 api.headers = apiProxy.setXHTTPMethodOverride(req.headers, api.headers);
28
29 dataAdapter.request(req, api, {
30 convertErrorCode: false
31 }, function(err, response, body) {
32 if (err) return next(err);
33
34 // Pass through statusCode.
35 res.status(response.statusCode);
36 if (!response.jsonp){
37 res.json(body);
38 }else{
39 res.jsonp(body);
40 }
41 });
42 };
43}
44
45apiProxy.getApiPath = function getApiPath(path) {
46 var sepIndex = path.indexOf(separator),

Callers 1

apiProxy.test.jsFile · 0.85

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected