res.json -> res.send, export app instance
This commit is contained in:
parent
1bcfa5be88
commit
e486e03705
|
@ -22,14 +22,14 @@ module.exports.create = function (options) {
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!dirnames || !dirnames.length) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dirnames.every(function (dirname) {
|
if (!dirnames.every(function (dirname) {
|
||||||
return 'string' === typeof dirname;
|
return 'string' === typeof dirname;
|
||||||
})) {
|
})) {
|
||||||
res.json({ error: "malformed request: " + JSON.stringify(dirnames) });
|
res.send({ error: "malformed request: " + JSON.stringify(dirnames) });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,9 @@ module.exports.create = function (options) {
|
||||||
// TODO opts.contents?
|
// TODO opts.contents?
|
||||||
fsapi.walk.walkDirs(options.blogdir, dirnames, opts).then(function (stats) {
|
fsapi.walk.walkDirs(options.blogdir, dirnames, opts).then(function (stats) {
|
||||||
if (!req.body.dirs && !req.query.dirs) {
|
if (!req.body.dirs && !req.query.dirs) {
|
||||||
res.json(stats[dirnames[0]]);
|
res.send(stats[dirnames[0]]);
|
||||||
} else {
|
} else {
|
||||||
res.json(stats);
|
res.send(stats);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -73,13 +73,13 @@ module.exports.create = function (options) {
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!filepaths || !filepaths.length) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fsapi.getfs(options.blogdir, filepaths).then(function (files) {
|
return fsapi.getfs(options.blogdir, filepaths).then(function (files) {
|
||||||
if (!req.body.paths && !req.query.paths) {
|
if (!req.body.paths && !req.query.paths) {
|
||||||
res.json(files[0]);
|
res.send(files[0]);
|
||||||
} else {
|
} else {
|
||||||
res.send(files);
|
res.send(files);
|
||||||
}
|
}
|
||||||
|
@ -97,13 +97,13 @@ module.exports.create = function (options) {
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!files || !files.length) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.tmpdir = options.tmpdir;
|
opts.tmpdir = options.tmpdir;
|
||||||
return fsapi.putfs(options.blogdir, files, opts).then(function (results) {
|
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) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fsapi.copyfs(options.blogdir, files, opts).then(function (results) {
|
return fsapi.copyfs(options.blogdir, files, opts).then(function (results) {
|
||||||
res.json(results);
|
res.send(results);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
|
|
13
server.js
13
server.js
|
@ -1,14 +1,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports.create = function (options) {
|
var path = require('path');
|
||||||
|
|
||||||
|
function create(options) {
|
||||||
var connect = require('connect')
|
var connect = require('connect')
|
||||||
, query = require('connect-query')
|
, query = require('connect-query')
|
||||||
, bodyParser = require('body-parser')
|
, bodyParser = require('body-parser')
|
||||||
, serveStatic = require('serve-static')
|
, serveStatic = require('serve-static')
|
||||||
, send = require('connect-send-json')
|
, send = require('connect-send-json')
|
||||||
|
|
||||||
, path = require('path')
|
|
||||||
|
|
||||||
, app = connect()
|
, app = connect()
|
||||||
, restful = require('./desirae-http-api').create(options)
|
, restful = require('./desirae-http-api').create(options)
|
||||||
;
|
;
|
||||||
|
@ -43,7 +43,7 @@ module.exports.create = function (options) {
|
||||||
var pathname = path.resolve(options.blogdir)
|
var pathname = path.resolve(options.blogdir)
|
||||||
;
|
;
|
||||||
|
|
||||||
res.json({
|
res.send({
|
||||||
path: pathname
|
path: pathname
|
||||||
, name: path.basename(pathname)
|
, name: path.basename(pathname)
|
||||||
, relativePath: path.dirname(pathname)
|
, relativePath: path.dirname(pathname)
|
||||||
|
@ -63,4 +63,7 @@ module.exports.create = function (options) {
|
||||||
;
|
;
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
module.exports = create({ blogdir: path.join(__dirname, 'blog') });
|
||||||
|
module.exports.create = create;
|
||||||
|
|
Loading…
Reference in New Issue