title: NuxtJS set Cookie in Middleware
body: <p>I'm building a nuxtjs app and try to set a cookie from a global middleware. I found <a href="https://github.com/nuxt/nuxt.js/issues/2507#issuecomment-355518211" rel="noreferrer">this</a> contribution on GitHub which shows a method to do this.</p>
  
  <p>So I implemented my middleware like this</p>
  
  <pre><code>export default function ({ isServer, res, query }) {
    if (query.lang) {
      if (isServer) {
        res.setHeader("Set Cookie", [`lang=${query.lang}`]);
      } else {
          document.cookie = `lang=${query.lang}`;
      }
    }
  }
  </code></pre>
  
  <p>My problem is that when I visit my app with <code>?lang=xxx</code> as a parameter, I'm always running into the else block of my if condition. So I get the error</p>
  
  <pre><code>document is not defined
  </code></pre>
  
  <p>Has anyone a idea what is wrong with my code. I can't see a difference to the code published on github.</p>