Skip to content

Instantly share code, notes, and snippets.

@daleharvey
Created October 20, 2015 13:40
Show Gist options
  • Save daleharvey/bf4e9a94553b75ef2d39 to your computer and use it in GitHub Desktop.
Save daleharvey/bf4e9a94553b75ef2d39 to your computer and use it in GitHub Desktop.
var proxy = require('express-http-proxy');
var DATA_DIR = '~';
var PouchDB = require('pouchdb').defaults({prefix: DATA_DIR + 'core/'});
var PublicPouchDB = PouchDB.defaults({prefix: DATA_DIR + 'public/'});
var app = require('express')();
app.use('/proxy', proxy('www.google.com', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
}
}));
// Lets make /db/ admin party access
app.use('/db/', require('pouchdb-express-router')(PouchDB));
// Lets make /public/ a read only instance
function reject(req, res, next) {
res.status(401).send({error: true, message: 'Unauthorised'});
}
app.post('/public/*', reject);
app.delete('/public/*', reject);
app.put('/public/*', reject);
app.use('/db/public', require('pouchdb-express-router')(PublicPouchDB));
@ermouth
Copy link

ermouth commented Oct 22, 2015

Use this with maximum care. express-http-proxy seems not to pipe, but rather recombine remote server response in memory first, and only then send it to user. In common scenarios this approach might be at least risky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment