title: NuxtJS Socket.io not working in production
body: <p>I am trying to use socket.io in a NuxtJS SSR app. But unfortunatly it only works on dev. As soon as I build and start in production it doesn't work anymore. I tried multiple ways of doing it (explained at the end), and I had always the same output. This version, using nuxt hooks, is the cleanest which works nice on dev.</p>
  <p>This is my server-side module (modules/ws.js) :</p>
  <pre class="lang-js prettyprint-override"><code>import socketIO from 'socket.io'
  
  export default function () {
    this.nuxt.hook('listen', (server, { host, port }) =&gt; {
      console.log(`ListentHook : Listening on http://${host}:${port}`)
      const io = socketIO(server)
  
      io.on('connection', (ws) =&gt; {
        console.log('Client connected')
        ws.on('message', (message) =&gt; {
          console.log('received: %s', message)
        })
        ws.emit('message', 'Hello new client')
      })
    })
  }
  </code></pre>
  <p>Client side, I have a plugin (plugins/socket.io.js) :</p>
  <pre class="lang-js prettyprint-override"><code>import io from 'socket.io-client'
  
  const socket = io('http://localhost:3000')
  
  export default socket
  </code></pre>
  <p>And on my vue, i import that client socket ang listen for messages (pages/index.vue) :</p>
  <pre class="lang-js prettyprint-override"><code>&lt;script&gt;
  import socket from '~/plugins/socket.io.js'
  
  export default {
    name: 'Index',
    beforeMount () {
      socket.on('message', this.printMsg)
    },
    methods: {
      printMsg (msg) {
        console.log(msg)
      }
    }
  }
  &lt;/script&gt;
  </code></pre>
  <p>And this is my nuxt.config.js file :</p>
  <pre class="lang-js prettyprint-override"><code>...
    buildModules: [
      '@nuxtjs/eslint-module',
      '@nuxtjs/tailwindcss',
      '~/modules/ws'
    ],
  ...
  </code></pre>
  <p>In development mode it work nicely.
  When I load http://localhost:3000 i get :</p>
  <blockquote>
  <p>&quot;Client connected&quot; on server side</p>
  </blockquote>
  <blockquote>
  <p>&quot;Hello new client&quot; on client side</p>
  </blockquote>
  <p>Now, when I build the application nothing works, and I only get an error in the client console :</p>
  <blockquote>
  <p>GET http://localhost:3000/socket.io/?EIO=4&amp;transport=polling&amp;t=NSauEZA
  404 (Not Found)</p>
  </blockquote>
  <p>I realy do not understand why.</p>
  <p><strong>What I already did :</strong></p>
  <p>Tested the official nuxt with-sockets example :
  <a href="https://github.com/nuxt/nuxt.js/tree/dev/examples/with-sockets" rel="nofollow noreferrer">https://github.com/nuxt/nuxt.js/tree/dev/examples/with-sockets</a>
  --&gt; Same results (Nuxt standalone version)</p>
  <p>Look up, and posted on that gitHub issue :
  <a href="https://github.com/nuxt/nuxt.js/issues/6928" rel="nofollow noreferrer">https://github.com/nuxt/nuxt.js/issues/6928</a>
  --&gt; Same results</p>
  <p>Tested to put .env variables
  --&gt; Same results (and with working env vars changing the actual server port)</p>
  <p>Thanks for your help !!
  And I can provide more code if needed !</p>