Created
November 18, 2014 00:02
-
-
Save daleharvey/5581d01757a4e4ecfd65 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
// index.js | |
'use strict'; | |
var app = require('express')(); | |
var PouchDB = require('pouchdb'); | |
require('./routes/db.js')(app, PouchDB); | |
require('./routes/document.js')(app, PouchDB); | |
app.listen(5985); | |
// routes/db.js | |
'use strict'; | |
var jsonParser = require('body-parser').json({limit: '1mb'}); | |
module.exports = function(app, PouchDB) { | |
// Create a database | |
app.put('/:db', jsonParser, function (req, res, next) { | |
var name = encodeURIComponent(req.params.db); | |
new PouchDB(name, function (err, db) { | |
if (err) return res.status(412).send(err); | |
res.status(201).send({ok: true}); | |
}); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment