我在使用最新版docpad的minicms docpad插件时遇到了问题。这个插件实现了server.extend函数,该函数正在传递一个opts对象,该对象包含docpad使用的express模块(在其插件初始化过程中)。 Minicms插件正在使用一堆expressJS中间件:
不幸的是,opts.express对象中没有这些中间件函数可用,我想知道最近的docpad版本是否有一些变化。是否有任何变通方法或docpad配置我应该注意?
minicms.plugin.js代码
// Generated by IcedCoffeeScript 1.3.3g
(function() {
var YAML, applyContext, cc, deepCopy, exec, fs, gm, sessionBridge, shellEscape, slugify, uuid,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
slugify = require('./utils/slugify');
cc = require('coffeecup');
uuid = require('node-uuid');
gm = require('gm');
fs = require('fs');
exec = require('child_process').exec;
shellEscape = require('./utils/shellEscape');
deepCopy = require('owl-deepcopy').deepCopy;
YAML = require('yamljs');
applyContext = require('./utils/applyContext');
sessionBridge = require('./utils/sessionBridge');
module.exports = function(BasePlugin) {
var MinicmsPlugin;
return MinicmsPlugin = (function(_super) {
__extends(MinicmsPlugin, _super);
function MinicmsPlugin() {
return MinicmsPlugin.__super__.constructor.apply(this, arguments);
}
MinicmsPlugin.prototype.name = 'minicms';
MinicmsPlugin.prototype.config = {
prefix: {
url: 'cms',
meta: 'cms'
},
validate: require('./utils/validate'),
sanitize: require('./utils/sanitize')
};
MinicmsPlugin.prototype.docpadReady = function(opts) {
return this.docpad.action('watch', {}, function(err) {
var _ref;
if (err) {
process.stderr.write(("" + ((_ref = err.message) != null ? _ref : err)).trim() + "\n");
}
return this.docpad.log("Force watching file for minicms.");
});
};
MinicmsPlugin.prototype.serverExtend = function(opts) {
var app, config, docpad, express;
app = opts.server;
express = opts.express; // express module
console.log(opts.express._router.middleware);
docpad = this.docpad;
config = this.config;
exec("rm -rf " + (shellEscape(docpad.config.srcPath + '/files/tmp')), function() {});
app.use('/' + this.config.prefix.url, express["static"](__dirname + '/static')); // express.static middleware
if (!(this.config.secret != null)) {
throw "Secret is required for cookie sessions (minicms)";
}
app.use(express.cookieParser()); // express.cookieParser middleware
app.use(express.cookieSession({ // express.cookieSession middleware
secret: this.config.secret
}));
app.get('/' + this.config.prefix.url + '/logout', require('./routes/logout').bind(this));
app.get('/' + this.config.prefix.url + '/login', require('./routes/login').bind(this));
app.post('/' + this.config.prefix.url + '/login', require('./routes/loginSubmit').bind(this));
app.get('/' + this.config.prefix.url, require('./routes/root').bind(this));
app.get('/' + this.config.prefix.url + '/:content/list', require('./routes/list').bind(this));
app.get('/' + this.config.prefix.url + '/:content/edit', require('./routes/edit').bind(this));
app.post('/' + this.config.prefix.url + '/:content/edit', require('./routes/edit').bind(this));
app.post('/' + this.config.prefix.url + '/generate', require('./routes/generate').bind(this));
console.log('/' + this.config.prefix.url + '/:content/:field/upload');
app.post('/' + this.config.prefix.url + '/:content/:field/upload', require('./routes/upload').bind(this));
};
return MinicmsPlugin;
})(BasePlugin);
};
}).call(this);