Skip to content

Commit

Permalink
HTTP shutdown is now setup in config not in startModule
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrue2 committed Oct 12, 2018
1 parent c5696cc commit eea1668
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gracenode",
"description": "A node.js framework for real-time applications over UDP and TCP protocols with extendable modules for quick and clean evelopment.",
"version": "3.9.20",
"version": "3.9.21",
"author": "Nobuyori Takahashi <[email protected]>",
"repository": {
"type": "git",
Expand Down
36 changes: 18 additions & 18 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ exports.config = function __httpConfig(configIn) {
route.setup();
request.setup();
response.setup();
gn.onExit(function HTTPShutdown(next) {
try {
logger.info('Stopping HTTP server...');
server.close();
logger.info(
'HTTP server stopped gracefully:',
config.host + ':' + config.port
);
next();
} catch (e) {
if (e.message === 'Not running') {
logger.verbose(e.message);
return next();
}
logger.error('HTTP server error on stop:', e);
next(e);
}
});
};

exports.info = function __httpInfo() {
Expand Down Expand Up @@ -151,24 +169,6 @@ exports.startModule = function (cb) {
);
cb(error);
});
gn.onExit(function __httpOnExit(next) {
try {
logger.info('Stopping HTTP server...');
server.close();
logger.info(
'HTTP server stopped gracefully:',
config.host + ':' + config.port
);
next();
} catch (e) {
if (e.message === 'Not running') {
logger.verbose(e.message);
return next();
}
logger.error('HTTP server error on stop:', e);
next(e);
}
});
try {
server.listen(config.port, config.host);
} catch (error) {
Expand Down

0 comments on commit eea1668

Please sign in to comment.