content icon indicating copy to clipboard operation
content copied to clipboard

watch config option : allow 0.0.0.0 mask

Open augnustin opened this issue 2 years ago • 12 comments

Is your feature request related to a problem? Please describe

I'm using nuxt content in a docker. Hence the ws URL is not localhost:4000 but 172.19.0.2:4000, which I can't connect to if the websocket network mask is not set to 0.0.0.0.

Describe the solution you'd like

Add a ws.mask option in nuxt content config.

Describe alternatives you've considered

Having a ws.url = 172.19.0.2:4000 option would also work but would be less comfortable to use and less generic.

For now, I simply have to disable the watch option.

Cheers

augnustin avatar Feb 21 '23 11:02 augnustin

Did you tried passing hostname to content.watch.ws options in nuxt.config?

Content Docs: https://content.nuxtjs.org/api/configuration#watch Listhen docs: https://github.com/unjs/listhen#hostname

farnabaz avatar Feb 23 '23 15:02 farnabaz

Thanks for your feedback.

I did not know about this listhen documentation. I guess it would be nice if it were mentioned in content doc.

I finally sorted myself out using:

// package.json
{
  scripts: {
    "dev": "HOSTNAME=$(hostname -i) && nuxt dev --port=5000",
  }
}
// nuxt.config.js
{
  content: {
    watch: {
      ws: {
        hostname: process.env.HOSTNAME,
      },
    },
  },
}

Slightly hacky solution, but it works :relaxed:

Should I close the issue?

augnustin avatar Feb 27 '23 15:02 augnustin

You are right, sadly we didn't describe this in the content documentation yet. We should improve docs.

farnabaz avatar Mar 08 '23 12:03 farnabaz

This issue is troublesome. We can't set reproductible dev environment with podman (or docker) since the websocket is not reachable !

@augnustin : your workaround implies a DNS entry on the client (and it triggers Chrome security that will probably prevent unsecured connection for non-localhost target)

The Content server is not consistent with Nuxt nor Vite :

  • Nuxt server can be forwarded in podman/docker with a -p 3000:3000
  • vite HMR server can be forwarded in podman/docker with a -p 24678:24678
  • Content server can't be forwarded !

PhE avatar Aug 09 '23 18:08 PhE

Hello, @danielroe, you do know if there is a way to re-use (or create a new one using Vite) the nuxt web socket connection? Currently, there is a custom (and manual) web socket connection created using web-socket.ts and in the module.ts. I'm clearly not an expert.

This manual connection is very annoying since we can't forward port (so no docker or docker tool based like code spaces and no remote dev) which is very annoying.

Thank you.

Barbapapazes avatar Aug 11 '23 12:08 Barbapapazes

Ok, I understand how the handleHotUpdate from a Vite plugin work. Now, I need to understand how to tell to Vite to handle update on md files.

Barbapapazes avatar Aug 11 '23 13:08 Barbapapazes

Ok, I understand how the handleHotUpdate from a Vite plugin work. Now, I need to understand how to tell to Vite to handle update on md files.

Maybe, it's not possible due to how it works but we can try using chokidar, like in Nuxt.

Barbapapazes avatar Aug 11 '23 13:08 Barbapapazes

Ok, I understand how the handleHotUpdate from a Vite plugin work. Now, I need to understand how to tell to Vite to handle update on md files.

Maybe, it's not possible due to how it works but we can try using chokidar, like in Nuxt.

Ok, I've chokidar set up. The question is now, how to send ws event using vite?

Barbapapazes avatar Aug 11 '23 13:08 Barbapapazes

Ok, I could have something.

EDIT:

 if (process.client && publicConfig.content.wsUrl) {
    // Connect to websocket
    // import('../composables/web-socket').then(({ useContentWebSocket }) => useContentWebSocket())
    if (import.meta.hot) {
      import.meta.hot.on('content:updated', () => {
        console.log('content updated !')
        refreshNuxtData()
      })
    }
  }

It seems cool!

Barbapapazes avatar Aug 11 '23 13:08 Barbapapazes

I will try this setup in a Codespace.

Barbapapazes avatar Aug 11 '23 13:08 Barbapapazes

But, how to have a working project in codespaces? mmmmh 🤔

Barbapapazes avatar Aug 11 '23 14:08 Barbapapazes

This issue is troublesome. We can't set reproductible dev environment with podman (or docker) since the websocket is not reachable !

@augnustin : your workaround implies a DNS entry on the client (and it triggers Chrome security that will probably prevent unsecured connection for non-localhost target)

The Content server is not consistent with Nuxt nor Vite :

  • Nuxt server can be forwarded in podman/docker with a -p 3000:3000
  • vite HMR server can be forwarded in podman/docker with a -p 24678:24678
  • Content server can't be forwarded !

Got the same issue. Content is unreachable to the frontend.

export default defineNuxtConfig({
  content: {
    watch: {
      ws: {
        hostname: process.env.CONTENT_HOST, // 0.0.0.0
        port: process.env.CONTENT_PORT, // 8000
        showURL: true
      }
    }
  }
})

I tried using 'localhost', '0.0.0.0', 'host.docker.internal'.

With 'host.docker.internal' I got this error: image

With 'localhost' and '0.0.0.0' I got this: image

lkjimy avatar Feb 12 '24 20:02 lkjimy