UNPKG

626 BJavaScriptView Raw
1module.exports = function(r, app, opts, NODE_ENV) {
2 var proxy = r('simple-http-proxy', 'silent');
3 var API_URL = opts.apiUrl;
4 if (!API_URL || NODE_ENV !== 'development' || !proxy) return;
5 API_URL = API_URL.replace(/^ws/, 'http');
6
7 app.useAfter('cookieParser', '/api', 'api-proxy', proxy(API_URL, {
8 xforward: opts.xforward,
9 onrequest: onrequest
10 }));
11};
12
13function onrequest(opts, req) {
14 delete opts.headers['if-none-match'];
15 delete opts.headers.connection;
16 if (!opts.headers.authorization && req.cookies && req.cookies._access_token) opts.headers.authorization = 'Bearer ' + req.cookies._access_token;
17}
\No newline at end of file