changed to cloudant

This commit is contained in:
Martin Donnelly 2016-12-22 15:25:50 +00:00
parent 2f2a736f46
commit 958e544024
2 changed files with 16 additions and 6 deletions

View File

@ -12,6 +12,7 @@
"basic-authentication": "^1.6.2",
"body-parser": "^1.15.0",
"cheerio": "^0.20.0",
"cloudant": "^1.6.2",
"cookie-parser": "^1.4.1",
"ejs": "^2.4.1",
"express": "^4.13.4",

View File

@ -23,19 +23,28 @@ var authOptions = {
var authentication =require('basic-authentication')(authOptions);
var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
var busEmitter = new EventEmitter();
var db_name = 'logger';
var dbCouch = nano.use(db_name);
var credentials = {
"username": "25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix",
"password": "8e417af1b0462ca55726848846cc6b8696fc76defe9d1864cbc334be59549e0c",
"host": "25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix.cloudant.com",
"port": 443,
"url": "https://25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix:8e417af1b0462ca55726848846cc6b8696fc76defe9d1864cbc334be59549e0c@25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix.cloudant.com",
"database" : "logger"
};
var Cloudant = require('cloudant');
var cloudant = Cloudant({account:credentials.username, password:credentials.password});
var dbCloudant = cloudant.db.use(credentials.database);
function insertLog(obj) {
logger.debug('Inserting into couch...');
logger.info(util.inspect(obj));
var newObj = {body:obj};
dbCouch.insert(newObj, function(err, body,header) {
dbCloudant.insert(newObj, function(err, body,header) {
if (err) {
logger.error('Error inserting into couch');
return;
@ -57,7 +66,7 @@ busEmitter.on('saveLog', doInsertLog);
router.get('/', authentication, function (req, res) {
logger.debug('list..');
dbCouch.view('body','body',function(err, body) {
dbCloudant.view('body','body',function(err, body) {
if (!err) {
var outJSON = [];
@ -86,7 +95,7 @@ router.get('/entry/:id', function (req, res) {
logger.debug(req.params.id);
dbCouch.get(req.params.id,function(err, body) {
dbCloudant.get(req.params.id,function(err, body) {
if (!err) {
var outJSON = {};