Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
function getServer() {
var server = new grpc.Server();
server.addService(echo.EchoService.service, {
echo: doEcho,
echoAbort: doEchoAbort,
serverStreamingEcho: doServerStreamingEcho,
});
return server;
}
if (require.main === module) {
// If this is run as a script, start a server on an unused port
var echoServer = getServer();
echoServer.bindAsync(
'0.0.0.0:9090', grpc.ServerCredentials.createInsecure(), (err, port) => {
assert.ifError(err);
echoServer.start();
});
}
exports.getServer = getServer;
const statusMap = {
"": proto.grpc.health.v1.HealthCheckResponse.ServingStatus.SERVING,
};
let healthImpl = new health.Implementation(statusMap);
server.addService(health.service, healthImpl);
if (process.argv.length >= 3) {
PORT = parseInt(process.argv[2], 10);
if (isNaN(PORT) || PORT < 1024 || PORT > 65535) {
console.log(`port ${process.argv[2]} should be integer between 1024-65535`);
process.exit(1);
}
}
console.log(`GRPC Bookstore server binding to port ${PORT}`);
server.bindAsync(`0.0.0.0:${PORT}`, grpc.ServerCredentials.createInsecure(), function (error, actualPort) {
if (error) {
console.log(error);
return;
}
if (actualPort !== PORT) {
console.log(`Binded to ${actualPort} instead of ${PORT}`);
return;
}
server.start();
console.log(`GRPC Bookstore server ready`);
});
}
await new Promise((resolve, reject) => {
this.server.bindAsync(`0.0.0.0:${this.port}`, grpc.ServerCredentials.createInsecure(), (err, port) => {
if (err) return reject(err)
log.info({ port: port }, 'server listening')
this.server.start()
return resolve()
})
})
}