-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
53 lines (42 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
var express = require('express');
var routes = {
'db': require('./lib/routes/db.js'),
'document': require('./lib/routes/document.js'),
'attachments': require('./lib/routes/attachments.js')
};
module.exports = function(PouchDB) {
var app = express.Router();
app.use(function (req, res, next) {
for (var prop in req.query) {
try {
req.query[prop] = JSON.parse(req.query[prop]);
} catch (e) {}
}
next();
});
app.get('/', function (req, res) {
res.status(200).send({'pouchdb-express-router': 'Welcome!'});
});
app.get('/_session', function (req, res) {
res.status(200).send({
'ok': true,
'userCtx':{"name":null,"roles":["_admin"]}
});
});
routes.db(app, PouchDB);
routes.attachments(app, PouchDB);
routes.document(app, PouchDB);
app.use(function (req, res) {
res.status(404).send( {
error: "not_found",
reason: "missing"
});
});
return app;
};
// Used for testing porpoises
// var PouchDB = require('pouchdb');
// var app = express();
// app.use(module.exports(PouchDB));
// app.listen(5985);