Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxi): call nuxt listen hook for dev #2772

Merged
merged 6 commits into from
Jan 18, 2022
Merged

feat(nuxi): call nuxt listen hook for dev #2772

merged 6 commits into from
Jan 18, 2022

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Jan 18, 2022

πŸ”— Linked issue

nuxt/bridge#149

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • [] ✨ New feature (a non-breaking change that adds functionality)
  • [] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The listen hook is a feature from nuxt v2 that is typed in nuxt v3. but nothing calls it (as far as I can tell).

It's a useful hook to expose the server used for local development, giving module authors functionality to see the server address and hook into the server if needed.

Specifically a module I'm working on needs it, this is the equivalent nuxt 2 code.

nuxt.hook('listen', (ctx) => {
  setServerContext({
    url: ctx.listeners[0].url,
    server: ctx.listeners[0].server,
    app: ctx.app,
  })
})

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly. - no hook documentation section, needs it's own page

The listen hook is useful to expose the address that the local development server is listening on, some third party modules will depend on fetching this reliably.

As far as I can tell the listen hook is unused in nuxt 3 so far, this types seem to be consistent with what was there, I've just typed it.
@netlify
Copy link

netlify bot commented Jan 18, 2022

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: 230df8d

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61e6a32fca88da0007a2841c

@harlan-zw harlan-zw changed the title feat(nuxi): implement missing listen hook fix(nuxi): implement missing listen hook Jan 18, 2022
@danielroe
Copy link
Member

This looks good to me.

Some context: nuxt/bridge#149.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks πŸ’š

@pi0 pi0 changed the title fix(nuxi): implement missing listen hook feat(nuxi): call nuxt listen hook Jan 18, 2022
@pi0 pi0 changed the title feat(nuxi): call nuxt listen hook feat(nuxi): call nuxt listen hook for dev Jan 18, 2022
@pi0 pi0 merged commit 4bd7ada into nuxt:main Jan 18, 2022
@fabianwohlfart
Copy link

Sorry, but is this already available? I am running nuxt 3.0.0-27398533.8edd481 and in build/start listen does not get fired.

@danielroe
Copy link
Member

@fabianwohlfart This PR only adds this hook in dev.

@fabianwohlfart
Copy link

@danielroe Is it possible at the moment to somehow hook onto the server and start a service, especially Socket.io? I have read nuxt/bridge#149 and not sure where things are or if i am just to blind to find the right resources...

@lewebsimple
Copy link
Contributor

lewebsimple commented Mar 25, 2022

Is the listen hook only called in development mode ?

Also, wouldn't it make sense to have listen:before / listen:after so we can initialize things before the server actually starts to listen ? This seems like a common use case for stuff like pre-establishing database connections

See this discussion

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants