Skip to content

Instantly share code, notes, and snippets.

@SlootSantos
Last active August 24, 2018 09:36
Show Gist options
  • Save SlootSantos/24caf09fc681a940d6134ca28bf715f6 to your computer and use it in GitHub Desktop.
Save SlootSantos/24caf09fc681a940d6134ca28bf715f6 to your computer and use it in GitHub Desktop.
// we create an express instance
// and we pull in the the function to create an gRPC client we defined before
const server = require('express')();
const createClient = require('../client');
// well.. this is on our localmachine
// hence we know for sure where what location this process has.
// in production you'd want to come up w/ something more flexible
const serviceDefinition = {
name: 'databaseService',
ipv4: '127.0.0.1',
port: 3000
};
// just a example response that our db could return
const exampleResponse = {
entries: [{
name: 'what',
value: 'ever you like'
},
{
name: 'what',
value: 'ever you like'
}]
};
// first start the server and
// then register at the discovery service
server
.get('/db', (_, res) => {
res.send(exampleResponse);
})
.listen(serviceDefinition.port, () => console.log(`DB service listens on ${serviceDefinition.port}`));
(async () => {
const client = await createClient();
const response = await client.register(serviceDefinition);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment