grpc-server-js
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -15,3 +15,3 @@ 'use strict'; | ||
const kHandlers = Symbol('handlers'); | ||
const kServer = Symbol('server'); | ||
const kServers = Symbol('servers'); | ||
const kStarted = Symbol('started'); | ||
@@ -56,3 +56,3 @@ const kOptions = Symbol('options'); | ||
this[kServer] = null; | ||
this[kServers] = []; | ||
this[kHandlers] = new Map(); | ||
@@ -120,4 +120,6 @@ this[kSessions] = new Set(); | ||
let server; | ||
if (creds._isSecure()) { | ||
this[kServer] = Http2.createSecureServer({ | ||
server = Http2.createSecureServer({ | ||
...http2ServerOptions, | ||
@@ -127,19 +129,18 @@ ...creds._getSettings() | ||
} else { | ||
this[kServer] = Http2.createServer(http2ServerOptions); | ||
server = Http2.createServer(http2ServerOptions); | ||
} | ||
this[kServer].timeout = 0; | ||
setupHandlers(this); | ||
server.timeout = 0; | ||
setupHandlers(this, server); | ||
function onError (err) { | ||
this[kServer] = null; | ||
callback(err, -1); | ||
} | ||
this[kServer].once('error', onError); | ||
this[kServer].listen(listenOptions, () => { | ||
const server = this[kServer]; | ||
server.once('error', onError); | ||
server.listen(listenOptions, () => { | ||
const port = server.address().port; | ||
server.removeListener('error', onError); | ||
this[kServers].push(server); | ||
callback(null, port); | ||
@@ -150,3 +151,8 @@ }); | ||
start () { | ||
if (this[kServer] === null || this[kServer].listening !== true) { | ||
const servers = this[kServers]; | ||
const ready = servers.length > 0 && servers.every((server) => { | ||
return server.listening === true; | ||
}); | ||
if (!ready) { | ||
throw new Error('server must be bound in order to start'); | ||
@@ -243,8 +249,9 @@ } | ||
this[kStarted] = false; | ||
this[kServers].forEach((server) => { | ||
if (server.listening === true) { | ||
pendingChecks++; | ||
server.close(maybeCallback); | ||
} | ||
}); | ||
if (this[kServer] !== null && this[kServer].listening === true) { | ||
pendingChecks++; | ||
this[kServer].close(maybeCallback); | ||
} | ||
// If any sessions are active, close them gracefully. | ||
@@ -264,5 +271,7 @@ pendingChecks += this[kSessions].size; | ||
// Close the server if it is still running. | ||
if (this[kServer] !== null && this[kServer].listening === true) { | ||
this[kServer].close(); | ||
} | ||
this[kServers].forEach((server) => { | ||
if (server.listening === true) { | ||
server.close(); | ||
} | ||
}); | ||
@@ -300,5 +309,3 @@ this[kStarted] = false; | ||
function setupHandlers (grpcServer) { | ||
const http2Server = grpcServer[kServer]; | ||
function setupHandlers (grpcServer, http2Server) { | ||
http2Server.on('stream', (stream, headers) => { | ||
@@ -305,0 +312,0 @@ const contentType = headers[HTTP2_HEADER_CONTENT_TYPE]; |
{ | ||
"name": "grpc-server-js", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Pure JavaScript gRPC Server", | ||
@@ -26,3 +26,3 @@ "author": "Colin J. Ihrig <cjihrig@gmail.com> (http://www.cjihrig.com/)", | ||
"devDependencies": { | ||
"@grpc/grpc-js": "^0.6.17", | ||
"@grpc/grpc-js": "^0.7.1", | ||
"@grpc/proto-loader": "0.5.x", | ||
@@ -29,0 +29,0 @@ "belly-button": "6.x.x", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55651
1568