Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating example.js, README

  • Loading branch information...
commit 11ebac4d1fee5f8a1149bf333ac65b0852eff37d 1 parent a5ba693
@yhahn yhahn authored
Showing with 60 additions and 26 deletions.
  1. +44 −13 README.md
  2. +16 −13 example.js
View
57 README.md
@@ -1,26 +1,57 @@
# Connect CouchDB
-connect-couchdb is a middleware session storage for connect framework
+`connect-couchdb` is a middleware session store for the connect framework.
-## Requirement
+## Requirements
- - cradle (v 0.1.0)
+- request 1.9.x
+- couchdb 1.0.x or higher
## Installation
-Via npm :
+Via npm:
- $ npm install connect-couchdb
+ $ npm install connect-couchdb
-If database doesn't exist, it will create it and setting views. If database
-already exist you'll need to setup views by running :
-`require('connect-couchdb').setup('yourdatabase').install()`
+## Usage
-## Example
+ var connect = require('connect'),
+ ConnectCouchDB = require('./lib/connect-couchdb')(connect);
-Take a look at `example.js` file to see an example of use.
+ var store = new connectCouchDB({
+ // Name of the database you would like to use for sessions.
+ name: 'myapp-sessions',
-## Options
+ // Optional. How often expired sessions should be cleaned up.
+ // Defaults to 600000 (10 minutes).
+ reapInterval: 600000,
+
+ // Optional. How often to run DB compaction against the session
+ // database. Defaults to 600000 (10 minutes).
+ compactInterval: 600000
+ });
+ var server = connect.createServer();
+ server.use(connect.session({secret: 'YourSecretKey', store: store });
+
+If the database specified doesn't already exist `connect-couch` will create it
+and setup its primary design document. It is highly recommended that you use
+a separate database for your sessions for performance of both the session
+views and any other document views you may have.
+
+See `example.js` file for an example connect server using `connect-couch`.
+
+## Tests
+
+ $ npm test
+
+## Author
+
+- tdebarochez
+
+## Contributors
+
+- ryankirkman
+- wankdanker
+- ianshward
+- yhahn
- - `database`: database name
- - ... all every parameters are passed to cradle.Connection()
View
29 example.js
@@ -1,20 +1,23 @@
var connect = require('connect'),
connectCouchDB = require('./lib/connect-couchdb')(connect);
-function helloWorld(req, res) {
- if (!req.session.tick) {
- req.session.tick = 0;
- }
+function helloWorld(req, res, next) {
+ if (req.url !== '/') return next();
+
+ req.session.tick = req.session.tick || 0;
+ req.session.tick++;
res.writeHead(200, { 'Content-Type': 'text/plain' });
- if (req.url == '/') {
- req.session.tick++;
- res.write('hello world : ' + req.session.tick);
- }
+ res.write('hello world : ' + req.session.tick);
res.end('');
}
-var server = connect.createServer(connect.cookieParser(),
- connect.session({secret: 'your secret passphrase',
- store: new connectCouchDB({name: "test"})}),
- helloWorld);
-server.listen(3000);
+var server = connect.createServer(
+ connect.cookieParser(),
+ connect.session({
+ secret: 'your secret passphrase',
+ store: new connectCouchDB({name: "test"})
+ }),
+ helloWorld
+);
+
+server.listen(3000);
Please sign in to comment.
Something went wrong with that request. Please try again.