Expressjs: proxy requests to Solr

To proxy requests to solr in ExpressJS, you can use the HTTP proxy:

npm install express-http-proxy --save

When you set this up, you can add the core (here called new_core), and any arguments you want added by default:

var proxy = require('express-http-proxy');
 
app.use('/execute', 
  proxy('http://localhost:8983', {
    forwardPath: function(req, res) {
      return '/solr/new_core/select?wt=json&indent=true&' + 
        require('url')
          .parse(req.url)
          .path
          .substring('execute/'.length);
    }
  }
));

This will pass anything that goes to “/execute” to your Solr core.

If you want a good Javascript book, I got a lot out of Secrets of the Javascript Ninja.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *