Created
August 29, 2022 15:11
-
-
Save notmedia/25bb4d183a5c62084e0b9d795585f75e 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 { Server, ServerCredentials } from '@grpc/grpc-js'; | |
import * as fs from 'fs'; | |
import * as path from 'path'; | |
import { TLSServiceServer, TLSServiceService } from './generated/proto/tls_service'; | |
const TLSService: TLSServiceServer = { | |
unary(call, callback) { | |
callback(null, call.request); | |
}, | |
}; | |
function getServerCredentials(): ServerCredentials { | |
const serverCert = fs.readFileSync(path.resolve(__dirname, '../certs/server-cert.pem')); | |
const serverKey = fs.readFileSync(path.resolve(__dirname, '../certs/server-key.pem')); | |
const serverCredentials = ServerCredentials.createSsl( | |
null, | |
[ | |
{ | |
cert_chain: serverCert, | |
private_key: serverKey, | |
}, | |
], | |
false | |
); | |
return serverCredentials; | |
} | |
function main() { | |
const server = new Server(); | |
const serverCredentials = getServerCredentials(); | |
server.addService(TLSServiceService, TLSService); | |
server.bindAsync('0.0.0.0:4000', serverCredentials, () => { | |
server.start(); | |
console.log('gRPC server started on 0.0.0.0:4000'); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment