title: Set cookie using express middleware
body: <p>I try to set a cookie on page load by extending the <code>apostrophe-express</code> module. But the console shows an error ... after successfully output <code>req.cookies</code> to it.</p>
  
  <p>Part of module's index.js:</p>
  
  <pre><code>module.exports = {
    extend: 'apostrophe-express',
    // [...]
    middleware: [
      function(req, res, next) {
        console.log(req.cookies); // Successful output.
        return next(); // App crashes.
      }
    ]
  };
  </code></pre>
  
  <p>Console output; user, app and cookie values replaced:</p>
  
  <pre><code>{ '[app].csrf': '[randomString]',
    '[app].sid':
     '[someId]' }
  /Users/[user]/Node/[app]/node_modules/apostrophe/lib/modules/apostrophe-templates/index.js:608
          req.browserCall('apos.pageReadyWhenCalm($("body"));');
              ^
  
  TypeError: req.browserCall is not a function
      at Object.self.renderPageForModule (/Users/[user]/Node/[app]/node_modules/apostrophe/lib/modules/apostrophe-templates/index.js:608:13)
      at /Users/[user]/Node/[app]/node_modules/apostrophe/lib/modules/apostrophe-module/index.js:349:31
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:726:13
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:52:16
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:264:21
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:44:16
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:723:17
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:167:37
      at /Users/[user]/Node/[app]/node_modules/apostrophe/index.js:128:16
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:52:16
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:264:21
      at /Users/[user]/Node/[app]/node_modules/async/lib/async.js:44:16
      at Immediate.&lt;anonymous&gt; (/Users/[user]/Node/[app]/node_modules/apostrophe/index.js:429:20)
      at runCallback (timers.js:696:18)
      at tryOnImmediate (timers.js:667:5)
      at processImmediate (timers.js:649:5)
  </code></pre>
  
  <p>What am I missing? <a href="https://stackoverflow.com/a/39807427/9244077">This answer</a> was my base for the middleware function.</p>
  
  <p>Edit: The same happens by returning <code>res.send('ok')</code> after setting the cookie.</p>