Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b02e8d002 | |||
| a2b2dc1a56 |
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-03-23 - 2.0.2 - fix(adapter.node)
|
||||||
|
close websocket server and active connections when stopping the Node adapter
|
||||||
|
|
||||||
|
- Store the WebSocketServer instance on the adapter so it can be closed during shutdown.
|
||||||
|
- Close all active HTTP connections before closing the underlying Node server to improve shutdown cleanup.
|
||||||
|
|
||||||
## 2025-12-20 - 2.0.1 - fix(readme)
|
## 2025-12-20 - 2.0.1 - fix(readme)
|
||||||
update README: rework features, add OpenAPI/Swagger, compression, request validation, examples, and runtime stats
|
update README: rework features, add OpenAPI/Swagger, compression, request validation, examples, and runtime stats
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartserve",
|
"name": "@push.rocks/smartserve",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a cross platform server module for Node, Deno and Bun",
|
"description": "a cross platform server module for Node, Deno and Bun",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartserve',
|
name: '@push.rocks/smartserve',
|
||||||
version: '2.0.1',
|
version: '2.0.2',
|
||||||
description: 'a cross platform server module for Node, Deno and Bun'
|
description: 'a cross platform server module for Node, Deno and Bun'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { BaseAdapter, type IAdapterCharacteristics, type TRequestHandler } from
|
|||||||
*/
|
*/
|
||||||
export class NodeAdapter extends BaseAdapter {
|
export class NodeAdapter extends BaseAdapter {
|
||||||
private server: plugins.http.Server | plugins.https.Server | null = null;
|
private server: plugins.http.Server | plugins.https.Server | null = null;
|
||||||
|
private wss: any = null;
|
||||||
|
|
||||||
get name(): 'node' {
|
get name(): 'node' {
|
||||||
return 'node';
|
return 'node';
|
||||||
@@ -92,8 +93,13 @@ export class NodeAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async stop(): Promise<void> {
|
async stop(): Promise<void> {
|
||||||
|
if (this.wss) {
|
||||||
|
this.wss.close();
|
||||||
|
this.wss = null;
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
|
this.server.closeAllConnections();
|
||||||
this.server.close((err) => {
|
this.server.close((err) => {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
else resolve();
|
else resolve();
|
||||||
@@ -254,19 +260,19 @@ export class NodeAdapter extends BaseAdapter {
|
|||||||
// Dynamic import of ws library
|
// Dynamic import of ws library
|
||||||
const { WebSocketServer } = await import('ws');
|
const { WebSocketServer } = await import('ws');
|
||||||
|
|
||||||
const wss = new WebSocketServer({ noServer: true });
|
this.wss = new WebSocketServer({ noServer: true });
|
||||||
|
|
||||||
// Get internal callbacks if typedRouter mode
|
// Get internal callbacks if typedRouter mode
|
||||||
const callbacks = (hooks as any)._connectionCallbacks as IWebSocketConnectionCallbacks | undefined;
|
const callbacks = (hooks as any)._connectionCallbacks as IWebSocketConnectionCallbacks | undefined;
|
||||||
const typedRouter = hooks.typedRouter;
|
const typedRouter = hooks.typedRouter;
|
||||||
|
|
||||||
this.server.on('upgrade', (request, socket, head) => {
|
this.server.on('upgrade', (request, socket, head) => {
|
||||||
wss.handleUpgrade(request, socket, head, (ws) => {
|
this.wss.handleUpgrade(request, socket, head, (ws: any) => {
|
||||||
wss.emit('connection', ws, request);
|
this.wss.emit('connection', ws, request);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
wss.on('connection', (ws: any, request: any) => {
|
this.wss.on('connection', (ws: any, request: any) => {
|
||||||
const peer = this.wrapNodeWebSocket(ws, request);
|
const peer = this.wrapNodeWebSocket(ws, request);
|
||||||
|
|
||||||
// Register connection if typedRouter mode
|
// Register connection if typedRouter mode
|
||||||
|
|||||||
Reference in New Issue
Block a user