Last active
August 29, 2022 17:33
-
-
Save notmedia/929bacbab8a5e9afce6087bc91b287a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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