(#122) - Mode support (custom, minimumForPouchDB & fullCouchDB)#155
(#122) - Mode support (custom, minimumForPouchDB & fullCouchDB)#155marten-de-vries wants to merge 1 commit intomasterfrom
Conversation
cb984c6 to
3f54f7e
Compare
lib/index.js
Outdated
There was a problem hiding this comment.
Here is defined what files a profile consists of: custom by default doesn't include anything at all; core is as close to pouchdb-express-router as I could get, pouchdb-complete contains everything.
|
@nolanlawson @daleharvey: I would normally timebomb this by now, but since this is a pretty big change I would like a +1 on the general concept (as described in my first post) first at least. Could one of you look at it? |
|
@marten-de-vries Sorry for not giving this a lookover sooner. Holidays. :) In general, I like this approach. It renders pouchdb-express-router obsolete, which makes me a lot less nervous, because we don't have to support two codebases. Just a few suggestions:
Of course, how confusing this system is will depend on how it's presented in the README. :) I think this is one of those unfortunate cases where the developers could not agree on a single option, so we are creating multiple options and inviting users to try to guess what our thought process was. But I think if we simply explain: "this one's the kitchen sink, it's a full CouchDB-like database, whereas this one is just the minimum you need for replication," then it should be clear. Also when this is complete, let's deprecate/unpublish express-pouchdb-router and remove it from the Travis tests. @daleharvey do you agree? |
|
Oh, and I also think |
|
@nolanlawson Good point about the file names. I'm not particularly attached to any specific names for the new options. Custom would still need |
|
Maybe As for |
|
I like the diff concept for cases like 'just add Fauxton' or 'authentication clashes with my own auth mechanism (e.g. because both support http basic auth), just disable express-pouchdb's'. I believe that with those two examples added to the readme, the concept will be clear enough and that it'll be worth it. But, if those use cases don't sound convincing enough, I guess I don't care enough about them to keep advocating their inclusion further and am ok with scrapping them. If that's the case, I suggest as api instead of |
|
Maybe I misunderstood what |
|
A concept version of what would be added to the readme. (It's incomplete, but hopefully enough to make a descision on profileDiff, which I renamed to overrideMode here. Examples haven't been run yet): APIexpress-pouchdb exports a single function that builds an express application object. Its function signature is:
Examples// Example 1: builds an HTTP API using all the defaults, and lets it listen on port 5985:
var app = require('express-pouchdb')(require('pouchdb'));
app.listen(5985);
// Example 2: builds an http api that exposes a minimal HTTP interface, but adds Fauxton
// as an extra to debug it.
var app = require('express-pouchdb')({
mode: 'minimumForPouchDB',
overrideMode: {
include: ['fauxton']
}
});
// when not specifying PouchDB as an argument to the main function, you need to specify
// it like this before requests are routed to ``app``
app.setPouchDB(require('pouchdb'));
// Example 3: builds a full HTTP API but excludes express-pouchdb's authentication logic
// (say, because it interferes with custom authentication logic used in our own express
// app):
var app2 = require('express-pouchdb')(require('pouchdb'), {
mode: 'fullCouchDB' // specified for clarity. It's the default so not necessary.
overrideMode: {
exclude: [
'routes/authentication',
// disabling the above, gives error messages which require you to disable the
// following parts too. Which makes sense since they depend on it.
'routes/authorization',
'routes/session'
]
}
}); |
|
Looking very good to me. A strong +1, but gonna wait for @daleharvey to second it since it's a big change. |
3f54f7e to
b231763
Compare
|
The commit above gets the code up-to-date with everything discussed so far. (snake_case -> kebab-case for files, profile -> mode, profileDiff -> overrideMode, core -> minimumForPouchDB & complete -> fullCouchDB). |
|
Oh, forgot to modify the commit message to use 'mode' instead of 'profile'. That can be fixed when merging. |
|
+1 |
|
Merged: 3920710 |
Adds the following options:
This allows users to specify exactly which parts of express-pouchdb need to be loaded. Dependencies are handled by a check to
app.includes[partThatsNeeded], often abstracted away viautils.requires.The order in which the routes are loaded is specified by index.js.
See for examples on how to use the included tests. The second argument ('opts') needs to be documented in README.md though.