Skip to content

Commit

Permalink
Merge 4cdee77 into 3199803
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed May 9, 2019
2 parents 3199803 + 4cdee77 commit d26c6a2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 43 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@

## Installation

Install module and required peer dependencies.

```
$ npm install mali
$ npm install mali grpc @grpc/proto-loader
```

## Example

```js
const path = require('path')
const Mali = require('mali')

const PROTO_PATH = path.resolve(__dirname, '../protos/helloworld.proto')

async function sayHello (ctx) {
ctx.res = { message: 'Hello '.concat(ctx.req.name) }
}

function main () {
const app = new Mali(PROTO_PATH)
const app = new Mali('helloworld.proto')
app.use({ sayHello })
app.start('127.0.0.1:50051')
}
Expand Down
4 changes: 4 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ class Mali extends Emitter {

if (handlers && hasHandlers) {
_.forOwn(handlers, (v, k) => {
if (!v) {
return
}

const md = methods[k]
const shortComposedKey = md.originalName || _.camelCase(md.name)

Expand Down
53 changes: 17 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
},
"peerDependencies": {
"grpc": "^1.11.0",
"@grpc/proto-loader": "^0.3.0 || ^0.4.0"
"@grpc/proto-loader": "^0.3.0 || ^0.4.0 || ^0.5.0"
},
"devDependencies": {
"@grpc/proto-loader": "^0.4.0",
"@grpc/proto-loader": "^0.5.0",
"async": "^2.6.2",
"ava": "^1.3.0",
"coveralls": "^3.0.2",
Expand Down
20 changes: 20 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ test.cb('app.start() with a default port from OS when no params given', t => {
app.close().then(() => t.end())
})

test.cb('app.start() should start and not throw with incomplete API', t => {
t.plan(5)
const PROTO_PATH = path.resolve(__dirname, './protos/transform.proto')

function upper (ctx) {
ctx.res = { message: ctx.req.message.toUpperCase() }
}

const app = new Mali(PROTO_PATH, 'TransformService')
t.truthy(app)
app.use({ upper })
const server = app.start()
t.truthy(server)
const ports = app.ports
t.truthy(ports)
t.is(ports.length, 1)
t.true(typeof ports[0] === 'number')
app.close().then(() => t.end())
})

test.cb('app.start() with a default port from OS with object param', t => {
t.plan(5)
const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto')
Expand Down

0 comments on commit d26c6a2

Please sign in to comment.