From e486e03705f66c81ee2aac0a62209bdf85cb8399 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 14 Jan 2015 05:14:11 -0500 Subject: [PATCH] res.json -> res.send, export app instance --- desirae-http-api.js | 20 ++++++++++---------- server.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/desirae-http-api.js b/desirae-http-api.js index df9fc9b..d2138b4 100644 --- a/desirae-http-api.js +++ b/desirae-http-api.js @@ -22,14 +22,14 @@ module.exports.create = function (options) { ; if (!dirnames || !dirnames.length) { - res.json({ error: "please specify GET w/ req.query.dir or POST w/ _method=GET&dirs=path/to/thing,..." }); + res.send({ error: "please specify GET w/ req.query.dir or POST w/ _method=GET&dirs=path/to/thing,..." }); return; } if (!dirnames.every(function (dirname) { return 'string' === typeof dirname; })) { - res.json({ error: "malformed request: " + JSON.stringify(dirnames) }); + res.send({ error: "malformed request: " + JSON.stringify(dirnames) }); return; } @@ -56,9 +56,9 @@ module.exports.create = function (options) { // TODO opts.contents? fsapi.walk.walkDirs(options.blogdir, dirnames, opts).then(function (stats) { if (!req.body.dirs && !req.query.dirs) { - res.json(stats[dirnames[0]]); + res.send(stats[dirnames[0]]); } else { - res.json(stats); + res.send(stats); } }); }; @@ -73,13 +73,13 @@ module.exports.create = function (options) { ; if (!filepaths || !filepaths.length) { - res.json({ error: "please specify GET w/ req.query.path or POST _method=GET&paths=path/to/thing,..." }); + res.send({ error: "please specify GET w/ req.query.path or POST _method=GET&paths=path/to/thing,..." }); return; } return fsapi.getfs(options.blogdir, filepaths).then(function (files) { if (!req.body.paths && !req.query.paths) { - res.json(files[0]); + res.send(files[0]); } else { res.send(files); } @@ -97,13 +97,13 @@ module.exports.create = function (options) { ; if (!files || !files.length) { - res.json({ error: "please specify POST w/ req.body.files" }); + res.send({ error: "please specify POST w/ req.body.files" }); return; } opts.tmpdir = options.tmpdir; return fsapi.putfs(options.blogdir, files, opts).then(function (results) { - res.json(results); + res.send(results); }); }; @@ -118,12 +118,12 @@ module.exports.create = function (options) { ; if ('object' !== typeof files || !Object.keys(files).length) { - res.json({ error: "please specify POST w/ req.body.files" }); + res.send({ error: "please specify POST w/ req.body.files" }); return; } return fsapi.copyfs(options.blogdir, files, opts).then(function (results) { - res.json(results); + res.send(results); }); }; // diff --git a/server.js b/server.js index 62506b7..84af71b 100644 --- a/server.js +++ b/server.js @@ -1,14 +1,14 @@ 'use strict'; -module.exports.create = function (options) { +var path = require('path'); + +function create(options) { var connect = require('connect') , query = require('connect-query') , bodyParser = require('body-parser') , serveStatic = require('serve-static') , send = require('connect-send-json') - , path = require('path') - , app = connect() , restful = require('./desirae-http-api').create(options) ; @@ -43,7 +43,7 @@ module.exports.create = function (options) { var pathname = path.resolve(options.blogdir) ; - res.json({ + res.send({ path: pathname , name: path.basename(pathname) , relativePath: path.dirname(pathname) @@ -63,4 +63,7 @@ module.exports.create = function (options) { ; return app; -}; +} + +module.exports = create({ blogdir: path.join(__dirname, 'blog') }); +module.exports.create = create;