Last active
September 26, 2017 23:28
-
-
Save cfsghost/2adc0066cec3da04c91b7dad70d9bb1f to your computer and use it in GitHub Desktop.
Groa.js : Koa-like gRPC Middleware Framework - router.js
This file contains 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
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