Created
October 20, 2015 13:40
-
-
Save daleharvey/bf4e9a94553b75ef2d39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.