How to use the @grpc/grpc-js.Server 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 GoogleCloudPlatform / esp-v2 / tests / endpoints / bookstore_grpc / grpc_server.js View on Github external
function main() {
  let server = new grpc.Server();

  // Bookstore service
  server.addService(bookstore_proto.Bookstore.service, {
    ListShelves: testDecorator(listShelves),
    CreateShelf: testDecorator(createShelf),
    GetShelf: testDecorator(getShelf),
    DeleteShelf: testDecorator(deleteShelf),
    ListBooks: testDecorator(listBooks),
    CreateBook: testDecorator(createBook),
    GetBook: testDecorator(getBook),
    DeleteBook: testDecorator(deleteBook),
  });

  // Health service following standard protocol
  const statusMap = {
    "": proto.grpc.health.v1.HealthCheckResponse.ServingStatus.SERVING,
github hyperledger-labs / weaver-dlt-interoperability / core / drivers / fabric-driver / server / server.ts View on Github external
* SPDX-License-Identifier: Apache-2.0
 */

import { Server, ServerCredentials, credentials } from '@grpc/grpc-js';
import ack_pb from '../protos-js/common/ack_pb';
import fabricView from '../protos-js/fabric/view_data_pb';
import query_pb from '../protos-js/common/query_pb';
import driver_pb_grpc from '../protos-js/driver/driver_grpc_pb';
import datatransfer_grpc_pb from '../protos-js/relay/datatransfer_grpc_pb';
import state_pb from '../protos-js/common/state_pb';
import invoke from './fabric-code';
import 'dotenv/config';
import { walletSetup } from './walletSetup';
import { Certificate } from '@fidm/x509';
import * as path from 'path';
const server = new Server();
console.log('driver def', JSON.stringify(driver_pb_grpc));

const mockedB64Data =
    'CkIIyAEaPRI7bG9jYWxob3N0OjkwODAvbmV0d29yazEvbXljaGFubmVsOnNpbXBsZXN0YXRlOlJlYWQ6QXJjdHVydXMa/AIKIFhDpf9CYfrxPkEtSWR8Kf+K5pBkSbx7VNYsAzijB+pnEtcCCoICEmYKCl9saWZlY3ljbGUSWAooCiJuYW1lc3BhY2VzL2ZpZWxkcy9pbnRlcm9wL1NlcXVlbmN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xNFAzWHJCUGZQSFdXeE1oWGhBaDNvUHNUOXdna1dHcFVmYWlybkd0bmRBQ3ZrSitNQi9nMUtPQjNUQ0IKMmpBT0JnTlZIUThCQWY4RUJBTUNCNEF3REFZRFZSMFRBUUgvQkFJd0FEQWRCZ05WSFE0RUZnUVVLMkFuM3RCTAprMVQyRGord0hHZ1RIQ3NiYmlZd0h3WURWUjBqQkJnd0ZvQVUxZyt0UG5naDJ3OGc5OXoxbXdzVmJrS2pBS2t3CklnWURWUjBSQkJzd0dZSVhjR1ZsY2pBdWIzSm5NUzV1WlhSM2IzSnJNUzVqYjIwd1ZnWUlLZ01FQlFZSENBRUUKU25zaVlYUjBjbk1pT25zaWFHWXVRV1ptYVd4cFlYUnBiMjRpT2lJaUxDSm9aaTVGYm5KdmJHeHRaVzUwU1VRaQpPaUp3WldWeU1DSXNJbWhtTGxSNWNHVWlPaUp3WldWeUluMTlNQW9HQ0NxR1NNNDlCQU1DQTBjQU1FUUNJQmFRCjhoTmRXd2xYeUhxY2htQzdzVUpWaER6Mkg2enh3M1BQS1I5M3lCL3NBaUJKMnpnQlhzL1lsMGZubnJNUXVCQUQKcDFBS1RKTkpsMVYwWUVHMFhiNXFwZz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0KEkcwRQIhAMyyvrcjHVc1oQmCNqZpH6nc0O+8wssXjwRcfmgxlhQAAiAqa0C8pSFNZNXiSVJHe948dJ0NU/y+7i5A55O0Frkz2Q==';

// Mocked fabric communication function
function mockCommunication(query: query_pb.Query) {
    console.log('Mock Communication');
    // Query object from requestor
    console.log('query', query.getRequestId());
    setTimeout(() => {
        console.log('Sending state');
        const meta = new state_pb.Meta();
        meta.setTimestamp(new Date().toISOString());
        meta.setProofType('Notarization');
        meta.setSerializationFormat('STRING');
github depscloud / depscloud / extractor / src / main.ts View on Github external
const matchersAndExtractors = extractors.map((extractor) => {
            return {
                matcher: new Matcher(extractor.matchConfig()),
                extractor,
            }
        });

        const impl: AsyncDependencyExtractor = new DependencyExtractorImpl(matchersAndExtractors);

        const healthcheck = new health.Implementation({
            "": healthv1.HealthCheckResponse.ServingStatus.SERVING,
        });
        // toggle the service health as such
        // healthcheck.setStatus("", healthv1.HealthCheckResponse.ServingStatus.NOT_SERVING);

        const server = new Server();
        server.addService(DependencyExtractor.service, unasyncify(impl));
        server.addService(health.service, healthcheck);

        let credentials = ServerCredentials.createInsecure();
        if (options.tlsKey && options.tlsCert && options.tlsCa) {
            const [ key, cert, ca ] = await Promise.all([
                asyncFs.readFile(options.tlsKey),
                asyncFs.readFile(options.tlsCert),
                asyncFs.readFile(options.tlsCa),
            ]);

            credentials = ServerCredentials.createSsl(ca, [ {
                private_key: key,
                cert_chain: cert,
            } ], true);
        }
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;
}
github andrewosh / hyperdrive-daemon / index.js View on Github external
async start () {
    await this.ready()
    this.server = new grpc.Server()

    if (hyperfuse) {
      this.server.addService(rpc.fuse.services.FuseService, {
        ...wrap(this.metadata, this.fuse.getHandlers(), { authenticate: true })
      })
    }
    this.server.addService(rpc.drive.services.DriveService, {
      ...wrap(this.metadata, this.drives.getHandlers(), { authenticate: true })
    })
    this.server.addService(rpc.main.services.HyperdriveService, {
      ...wrap(this.metadata, this.createMainHandlers(), { authenticate: true })
    })

    await new Promise((resolve, reject) => {
      this.server.bindAsync(`0.0.0.0:${this.port}`, grpc.ServerCredentials.createInsecure(), (err, port) => {
        if (err) return reject(err)