feat(dev, node-server): support a hook to access Node.js server instance
๐ Linked issue
solve https://github.com/unjs/nitro/issues/2040
โ Type of change
- [ ] ๐ Documentation (updates to the documentation, readme, or JSdoc annotations)
- [ ] ๐ Bug fix (a non-breaking change that fixes an issue)
- [ ] ๐ Enhancement (improving an existing functionality like performance)
- [x] โจ New feature (a non-breaking change that adds functionality)
- [ ] ๐งน Chore (updates to the build process or auxiliary tools and libraries)
- [ ] โ ๏ธ Breaking change (fix or feature that would cause existing functionality to change)
๐ Description
Hi ๐ this PR can be possible to enable WebSocket and Web Server to share the same port without the need for reverse proxy.
๐ Checklist
- [x] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.
When will this PR be added to the main branch?
I propose to expand these events
const server =
cert && key
? new HttpsServer({ key, cert }, toNodeListener(nitroApp.h3App))
: new HttpServer(toNodeListener(nitroApp.h3App));
// others code
nitroApp.hooks.callHook("node.server.init", server);
server.on('upgrade', (req: IncomingMessage) => {
nitroApp.hooks.callHook("node.server.upgrade", server, req);
})
server.on('listening', () => {
nitroApp.hooks.callHook("node.server.listening", server);
})
So much more stable for more control. For example, a handshake for WebSocket and the event that the server has started. As well as initialization which will make it possible to register more events for advanced users
When will this PR be added to the main branch?
I'm so sorry for the delay in progressing the PR due to my unfamiliarity with GitHub functionalities; I'm actively learning and seeking guidance to contribute effectively to the project.
Sorry for delay on this. I guess now that we have official WebSocket support, it should be less priority but I will defneitly investigate how to make it an extendable addon before introducing ๐๐ผ