Skip to content

volvoxjs/volvox-express-consul-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Volvox - Self announcing services

volvox.js express and consul sample

Server

import Volvox from 'volvox-core';
import vconsul from 'volvox-consul';
import vexpress from 'volvox-express';

import express from 'express'

async function main() {
    let server = express();

    server.get('/customers', (req, res) => {
       res.send({
            customerName: "Test customer",
            customerId: 666
        });
    });

    let volvox = new Volvox(vconsul(), vexpress());
    await volvox.bootstrap(server, "customers", "v1");
}

main();

Call service instance from client

import Volvox from 'volvox-core';
import vconsul from 'volvox-consul';
import request from 'request-promise';

async function main() {
    let volvox = new Volvox(vconsul());
    await volvox.bootstrapClient();
    
    let instance = await volvox.findServiceInstanceAsync("customers");
    let body = await request(`http://${instance.address}:${instance.port}/customers`);
    console.log(body);
}

main();

Stay tuned, more coming soon!

Releases

No releases published

Packages

No packages published