server/bo_client/server/proxies/bnf-sparql.js
author ymh <ymh.work@gmail.com>
Tue, 22 Nov 2016 18:33:07 +0100
changeset 433 65e357e5eecb
parent 305 ff6cf3fc5f40
permissions -rw-r--r--
correct document permalinks in notice and share buttons

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

const proxyPath = '/proxy/bnf-sparql';

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;
    req.url = req.url.slice(1);
    proxy.web(req, res, {target: 'http://data.bnf.fr/sparql'});
  });
};