Socket
Socket
Sign inDemoInstall

server-shutdown

Package Overview
Dependencies
4
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

7

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## [1.0.1] - 2017-05-27
### Fixed
- memory leak caused by not releasing socket.io sockets
## [1.0.0] - 2017-03-10

@@ -28,5 +32,6 @@ ### Added

[Unreleased]: https://github.com/MitMaro/node-server-shutdown/compare/1.0.0...HEAD
[Unreleased]: https://github.com/MitMaro/node-server-shutdown/compare/1.0.1...HEAD
[1.0.1]: https://github.com/MitMaro/node-server-shutdown/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/MitMaro/node-server-shutdown/compare/0.3.0...1.0.0
[0.3.0]: https://github.com/MitMaro/node-server-shutdown/compare/0.2.0...0.3.0
[0.2.0]: https://github.com/MitMaro/node-server-shutdown/compare/0.1.0...0.2.0

5

package.json
{
"name": "server-shutdown",
"version": "1.0.0",
"version": "1.0.1",
"description": "Gracefully shutdown any number of HTTP and WebSocket servers in node",

@@ -34,3 +34,4 @@ "main": "src/index.js",

"Tim Oram <mitmaro@gmail.com>",
"Whymarrh Whitby <whymarrh.whitby@gmail.com>"
"Whymarrh Whitby <whymarrh.whitby@gmail.com>",
"Gautam Chaudhary <gkcgautam@gmail.com>"
],

@@ -37,0 +38,0 @@ "license": "ISC",

@@ -22,34 +22,37 @@ # Server Shutdown

npm install server-shutdown
npm install --save server-shutdown
## Usage
const http = require('http');
const https = require('https');
const ServerShutdown = require('server-shutdown');
const serverShutdown = new ServerShutdown();
```ecmascript 6
const http = require('http');
const https = require('https');
const ServerShutdown = require('server-shutdown');
const serverShutdown = new ServerShutdown();
const httpServer = http.createServer((req, res) => {
res.end('HTTP response');
}).listen(80);
const httpServer = http.createServer((req, res) => {
res.end('HTTP response');
}).listen(80);
const httpsServer = https.createServer((req, res) => {
res.end('HTTPS response');
}).listen(443);
const httpsServer = https.createServer((req, res) => {
res.end('HTTPS response');
}).listen(443);
serverShutdown.registerServer(httpServer);
serverShutdown.registerServer(httpsServer);
serverShutdown.registerServer(httpServer);
serverShutdown.registerServer(httpsServer);
process.on('SIGTERM', () => {
serverShutdown.shutdown(() => {
console.log('All servers shutdown gracefully');
})
}));
process.on('SIGTERM', () => {
serverShutdown.shutdown(() => {
console.log('All servers shutdown gracefully');
});
});
```
## Adding Socket.io
// continuing from basic uasge
const socketio = require('socket.io');
const io = socketio(httpServer);
serverShutdown.registerServer(io, ServerShutdown.Adapters.socketio);
```ecmascript 6
// continuing from basic uasge
const socketio = require('socket.io');
const io = socketio(httpServer);
serverShutdown.registerServer(io, ServerShutdown.Adapters.socketio);
```

@@ -56,0 +59,0 @@ ## API

@@ -15,8 +15,3 @@ 'use strict';

callback();
},
socketClose(socket) {
debug('Disconnecting SocketIO socket');
socket.disconnect(true);
debug('SocketIO socket disconnected');
}
};

@@ -69,4 +69,7 @@ 'use strict';

async.parallel(tasks, () => {
this.sockets = new Set();
this.servers = new Set();
debug('Shutdown complete');
(callback || noop)();
this.stopped = false;
});

@@ -80,6 +83,11 @@ }

this.sockets.add(socket);
// some sockets use close, others use disconnect
socket.on('close', () => {
debug('Connection ended');
debug('Connection closed');
this.sockets.delete(socket);
});
socket.on('disconnect', () => {
debug('Connection disconnected');
this.sockets.delete(socket);
});
}

@@ -86,0 +94,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc