docpad plugins server.extend argument options not containing any express middleware with last version of docpad

153 Views Asked by At

I faced problems using minicms docpad plugin with last version of docpad. This plugin implements server.extend function which is being passed an opts object containing the express module used by docpad (during its plugin initialisation process). Minicms plugin is making use of a bunch of expressJS middleware :

  • express.static()
  • express.cookieParser()
  • express.cookieSession()

Unfortunately none of those middleware functions are available in the opts.express object and i'm wondering if there's been some changes in the recent docpad versions. Is there any workaround or docpad configuration i should be aware of ?

minicms.plugin.js code

// 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);
0

There are 0 best solutions below