Skip to content

Instantly share code, notes, and snippets.

@notmedia
Last active August 29, 2022 17:33
Show Gist options
  • Save notmedia/929bacbab8a5e9afce6087bc91b287a4 to your computer and use it in GitHub Desktop.
Save notmedia/929bacbab8a5e9afce6087bc91b287a4 to your computer and use it in GitHub Desktop.
import { ChannelCredentials } from '@grpc/grpc-js';
import * as fs from 'fs';
import * as path from 'path';
import { TLSServiceClient } from './generated/proto/tls_service';
function getChannelCredentials(): ChannelCredentials {
const rootCert = fs.readFileSync(path.resolve(__dirname, '../certs/ca-cert.pem'));
// If you use CA root certificate
// const channelCredentials = ChannelCredentials.createSsl();
// If you use Self-Signed root certificate you need to provide it
const channelCredentials = ChannelCredentials.createSsl(rootCert);
return channelCredentials;
}
function main() {
const credentials = getChannelCredentials();
const client = new TLSServiceClient('0.0.0.0:4000', credentials);
client.unary({ id: 'test' }, (error, response) => {
// eslint-disable-next-line no-console
console.log('response: ', response);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment