Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// uses the network name to create a unique wallet path
const walletPath = path.join(process.cwd(), `wallet-${process.env.NETWORK_NAME}`);
if (process.env.CONNECTION_PROFILE) {
walletSetup(
walletPath,
process.env.CONNECTION_PROFILE,
process.env.NETWORK_NAME ? process.env.NETWORK_NAME : 'network1',
);
} else {
console.error('No CONNECTION_PROFILE provided in the .env');
}
};
// SERVER: Start the server with the provided url.
// TODO: We should have credentials locally to ensure that the driver can only communicate with the local relay.
server.bindAsync(`${process.env.DRIVER_ENDPOINT}`, ServerCredentials.createInsecure(), (cb) => {
configSetup().then(() => {
server.start();
});
});
}
});
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);
}
const bindAddress = options.bindAddress || "0.0.0.0";
const httpPort = options.httpPort || 8080;
const grpcPort = options.port || options.grpcPort || 8090;
bind (port, creds) {
if (this[kStarted] === true) {
throw new Error('server is already started');
}
if (typeof port === 'number') {
port = `localhost:${port}`;
}
if (creds === null || typeof creds !== 'object') {
creds = ServerCredentials.createInsecure();
}
return new Promise((resolve, reject) => {
this.bindAsync(port, creds, (err, boundPort) => {
if (err) {
reject(err);
}
resolve(boundPort);
});
});
}