2015-01-13 11:22:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-01-14 10:14:11 +00:00
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
function create(options) {
|
2015-01-13 21:50:17 +00:00
|
|
|
var connect = require('connect')
|
|
|
|
, query = require('connect-query')
|
|
|
|
, bodyParser = require('body-parser')
|
|
|
|
, serveStatic = require('serve-static')
|
|
|
|
, send = require('connect-send-json')
|
|
|
|
|
|
|
|
, app = connect()
|
|
|
|
, restful = require('./desirae-http-api').create(options)
|
|
|
|
;
|
|
|
|
|
|
|
|
app
|
|
|
|
.use(send.json())
|
|
|
|
.use(query())
|
|
|
|
.use(bodyParser.json({ limit: 10 * 1024 * 1024 })) // 10mb
|
|
|
|
.use(require('compression')())
|
|
|
|
;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Keeping the API *required* by desirae super minimal
|
|
|
|
// so that it can be implemented easily in any language
|
|
|
|
//
|
|
|
|
app
|
|
|
|
.use('/api/fs/static', serveStatic(options.blogdir))
|
|
|
|
.use('/api/fs/walk', restful.walk)
|
|
|
|
.use('/api/fs/files', restful.getFiles)
|
|
|
|
.use('/api/fs/files', restful.putFiles)
|
|
|
|
.use('/api/fs/copy', restful.copy)
|
|
|
|
;
|
|
|
|
// end Desirae API
|
|
|
|
|
|
|
|
if (options.tmpdir) {
|
|
|
|
app.use(serveStatic(options.tmpdir));
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is used by DearDesi, but not required for desirae
|
|
|
|
app
|
|
|
|
.use('/api/fs/rootdir', function (req, res) {
|
|
|
|
var pathname = path.resolve(options.blogdir)
|
2015-01-13 11:22:20 +00:00
|
|
|
;
|
|
|
|
|
2015-01-14 10:14:11 +00:00
|
|
|
res.send({
|
2015-01-13 11:22:20 +00:00
|
|
|
path: pathname
|
|
|
|
, name: path.basename(pathname)
|
|
|
|
, relativePath: path.dirname(pathname)
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
})
|
2015-01-13 21:50:17 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
app
|
|
|
|
// the AngularJS App
|
|
|
|
.use(serveStatic(__dirname))
|
|
|
|
// TODO change file requests to '/blog'
|
|
|
|
//.use(serveStatic(options.blogdir))
|
|
|
|
.use('/blog', serveStatic(options.blogdir))
|
|
|
|
.use('/compiled_dev', serveStatic(path.join(options.blogdir, '/compiled_dev')))
|
2015-01-15 06:41:52 +00:00
|
|
|
.use('/compiled', serveStatic(path.join(options.blogdir, '/compiled')))
|
2015-01-13 21:50:17 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
return app;
|
2015-01-14 10:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = create({ blogdir: path.join(__dirname, 'blog') });
|
|
|
|
module.exports.create = create;
|