UNPKG

376 BJavaScriptView Raw
1module.exports = function(r, app, opts) {
2 var API_URL = opts.apiUrl;
3 var HyperClient = r('hyperagent');
4 if (!API_URL || !HyperClient) return;
5 API_URL = API_URL.replace(/^ws/, 'http');
6
7 app.useBefore('router', function hyperclient(req, res, next) {
8 // TODO setup caching
9 req.hyperclient = new HyperClient(req.get('x-api-url') || API_URL);
10 next();
11 });
12};
\No newline at end of file