node package manager

node-couchdb-proxy

ExpressJS CouchDB proxy middleware

Use cases:

  • proxying client-side requests to CouchDB hosted from localhost
  • disabling POST/PUT/DELETE requests on db or particular document
  • etc

Usage:

const express = require("express");
const app = express();
const couchProxy = require("node-couchdb-proxy")({
  url: "http://user:password@192.168.1.100:5984", // Defaults to http://localhost:5984 
  entries: ["documents1", "_users", "_session"], // Specify your database names here. Don't forget to specify system entries like _users or _session if needed. Defaults to ["_users", "_session"] 
  restrictMethod: "next", //"next" - will call next middleware/route, "unauthorized" - will return "401 Unauthorized", defaults to "unauthorized" 
  onRequest: req => { // Custom request handling logic here, You can return false to restrict request by given restrictMethod. Dont forget to return true in the end. 
    if (
      req.originalUrl == "/documents1/readonly_document" &&
      req.method == "PUT" // Disable writes on /documents1/readonly_document 
    ){
        return false;
    }
    return true;
  }
});
app.use(couchProxy);
app.get("/", (req, res) => res.send("homepage"));
app.listen(3000);