title: How Can I Use Express.js Middleware in a Keystone.js Project?
body: <p>I'm currently building a <a href="http://keystonejs.com/" rel="nofollow">Keystone.js</a> project, and need to use some <a href="http://expressjs.com/" rel="nofollow">Express.js</a> middleware libraries with it. Since Keystone.js is built on top of Express.js, this seemed like it would be fairly easy, but I'm running into lots of issues getting things working so far.</p>
  
  <p>Here's what I'm currently trying (this is my best guess as to the correct way to do this):</p>
  
  <p>In my <code>keystone.js</code> file (the app's main entrypoint), I'm inserting the following code directly before <code>keystone.start()</code>:</p>
  
  <pre><code>keystone.app.use(stormpath.init(keystone.app, {
    ...
  }));
  </code></pre>
  
  <p>The important bit here is the <code>keystone.app.use(...);</code> bit -- I took a look at the Keystone.js source, and it appears that the underlying Express.js application object is exposed as <code>keystone.app</code>, which is why I'm attempting to use it this way.</p>
  
  <p>Unfortunately, while my Keystone web server starts when running <code>$ node keystone.js</code>, trying to load any page on my site results in the following exception:</p>
  
  <pre><code>$ node keystone.js
  
  ------------------------------------------------
  KeystoneJS Started:
  keystone is ready on port 3000
  ------------------------------------------------
  
  TypeError: Object #&lt;Object&gt; has no method 'regenerate'
      at doSignin (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/lib/session.js:38:15)
      at Promise.&lt;anonymous&gt; (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/lib/session.js:72:5)
      at Promise.&lt;anonymous&gt; (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
      at Promise.EventEmitter.emit (events.js:95:17)
      at Promise.emit (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38)
      at Promise.fulfill (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20)
      at Promise.resolve (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/lib/promise.js:114:23)
      at Promise.&lt;anonymous&gt; (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
      at Promise.EventEmitter.emit (events.js:95:17)
      at Promise.emit (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38)
      at Promise.fulfill (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20)
      at /Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/lib/query.js:1400:13
      at model.Document.init (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/lib/document.js:250:11)
      at completeOne (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/lib/query.js:1398:10)
      at Object.cb (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/lib/query.js:1155:11)
      at Object._onImmediate (/Users/rdegges/Dropbox/Code/testing/keystone/node_modules/keystone/node_modules/mongoose/node_modules/mquery/lib/utils.js:137:16)
  </code></pre>
  
  <p>I've got MongoDB running locally just fine, and if I comment out my code above things work as expected, so I know this is the root cause.</p>
  
  <p>Any help would be appreciated.</p>