How to use the @grpc/grpc-js.ServerCredentials function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grpc / grpc-web / net / grpc / gateway / examples / echo / node-server / server.js View on Github external
*/
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;
github GoogleCloudPlatform / esp-v2 / tests / endpoints / bookstore_grpc / grpc_server.js View on Github external
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`);
  });
}
github andrewosh / hyperdrive-daemon / index.js View on Github external
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()
      })
    })
  }