Skip to content

Instantly share code, notes, and snippets.

@cfsghost
Last active September 26, 2017 23:28
Show Gist options
  • Save cfsghost/2adc0066cec3da04c91b7dad70d9bb1f to your computer and use it in GitHub Desktop.
Save cfsghost/2adc0066cec3da04c91b7dad70d9bb1f to your computer and use it in GitHub Desktop.
Groa.js : Koa-like gRPC Middleware Framework - router.js
const Groa = require('groa');
const Router = require('groa-router');
const app = new Groa();
const router = new Router();
// Add proto file
app.addProto(__dirname + '/router.proto');
// package: example.foo
// service: Example1
// method: Ping
router.rpc('/example.foo.Example1/Ping', async (ctx) => {
console.log('Ping');
ctx.body = ctx.req.body;
});
// package: example.foo
// service: Example1
// method: Echo
router.rpc('/example.foo.Example1/Echo', async (ctx) => {
console.log('Echo');
ctx.body = ctx.req.body;
});
// Add router middleware
app.use(router.routes());
// package: example.foo
// service: Example1
// method: Hello
router.rpc('/example.foo.Example1/Hello', async (ctx) => {
console.log('Hello');
ctx.body = {
msg: 'Hello!'
};
});
// Add router middleware
app.use(router.routes());
app.listen(50051, () => {
console.log('Listening on port 50051');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment