server/bo_client/server/proxies/bnf.js
author ymh <ymh.work@gmail.com>
Wed, 23 Nov 2016 08:12:23 +0100
changeset 438 4324a915e61b
parent 305 ff6cf3fc5f40
permissions -rw-r--r--
Added tag 0.0.12 for changeset 7693515f2e4a

/* jshint node:true */
/* eslint-env node */
/* eslint global-require: 0, no-magic-numbers: 0 */

const proxyPath = '/proxy/bnf';

module.exports = function(app) {
  // For options, see:
  // https://github.com/nodejitsu/node-http-proxy
  const proxy = require('http-proxy').createProxyServer({});

  proxy.on('error', function(err, req) {
    console.error(err, req.url); /* eslint no-console: 0 */
  });

  app.use(proxyPath, function(req, res/* , next */) {
    // include root path in proxied request
    req.url = proxyPath + '/' + req.url;
    proxy.web(req, res, {target: 'http://data.bnf.fr/search-letter/'});
  });
};