N
Nuxtβ€’4mo ago
proudparrot2

Serving Nuxt with an Express server

I want to serve Nuxt inside an Express server. Is this possible? The reason I want to do this is because I have a function that handles incoming websocket requests and deals with them accordingly Currently using express alongside a node:http server
httpServer.on('upgrade', (req, socket, head) => {
route(req, socket, head)
})
httpServer.on('upgrade', (req, socket, head) => {
route(req, socket, head)
})
10 Replies
manniL
manniLβ€’4mo ago
why not use websockets in nuxt + nitro directly? https://www.youtube.com/watch?v=OfY7JcrqkPg
Alexander Lichter
YouTube
Integrating WebSockets in Nuxt and Nitro
πŸŽ‰ Nitro 2.9 was released just before Vue.js Amsterdam and brings new features such as a database layer, a task API and also WebSocket support! But how can we integrate it in a Nuxt application? This video will teach you πŸ‘Œ Key points: πŸ›  How to set up WebSockets in Nitro and in Nuxt πŸ’‘ Working from scratch to a functional application ⚠️ Hints to m...
proudparrot2
proudparrot2β€’4mo ago
Does it function the same way as node:http's upgrade listener?
manniL
manniLβ€’4mo ago
Nope, not exactly. Shown in the code/video
proudparrot2
proudparrot2β€’4mo ago
Got it. Is there a way to achieve my previous request? Serving Nuxt through Express?
manniL
manniLβ€’4mo ago
You probably can but I never did πŸ™‚ You can serve express through nuxt though if that helps πŸ˜„
fsyntax
fsyntaxβ€’4mo ago
Could elaborate on that? Im basically looking for a way to serve an express app through nitro/nuxt, but can't really find any informations
manniL
manniLβ€’4mo ago
build your app as usual, then register the handler either in a catchall route (e.g. /api/[...].ts) or register it as handler via https://nuxt.com/docs/api/nuxt-config#serverhandlers
Nuxt
Nuxt Configuration
Discover all the options you can use in your nuxt.config.ts file.
manniL
manniLβ€’4mo ago
I'd love to hear why it has to be an express app though and nitro "isn't enough" πŸ˜‹
fsyntax
fsyntaxβ€’4mo ago
Thanks for the respone! I'll checkt that out πŸ™‚ Well, unfortunately PayloadCMS is built using express.js, im still kind of trying to wrap my head around if it's possible to let a nuxt app and payload run on the same port, though the more i think about it, the more i feel like its quite a lot work πŸ˜„
manniL
manniLβ€’4mo ago
might work as described above πŸ€” ^ ahh, I see
Want results from more Discord servers?
Add your server