Skip to content

Commit

Permalink
Merge pull request #36 from malijs/server_options
Browse files Browse the repository at this point in the history
update dependencies. Add start() grpc.Server options to fix #34
  • Loading branch information
bojand committed Jun 19, 2018
2 parents 172a9cb + 2f63655 commit dac2c58
Show file tree
Hide file tree
Showing 7 changed files with 1,726 additions and 1,625 deletions.
5 changes: 3 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Represents a gRPC service
* [.addService(proto, name, options)](#MaliaddService)
* [.use(service, name, ...fns)](#Maliuse)
* [.onerror(err)](#Malionerror)
* [.start(port, creds)](#Malistart) ⇒ <code>Object</code>
* [.start(port, creds, options)](#Malistart) ⇒ <code>Object</code>
* [.close()](#Maliclose)
* [.toJSON()](#MalitoJSON) ⇒ <code>Object</code>
* [.inspect()](#Maliinspect) ⇒ <code>Object</code>
Expand Down Expand Up @@ -214,7 +214,7 @@ Default error handler.

<a name="malistart" id="malistart" data-id="malistart"></a>

#### mali.start(port, creds) ⇒ <code>Object</code>
#### mali.start(port, creds, options) ⇒ <code>Object</code>
Start the service. All middleware and handlers have to be set up prior to calling <code>start</code>.

**Kind**: instance method of [<code>Mali</code>](#Mali)
Expand All @@ -224,6 +224,7 @@ Start the service. All middleware and handlers have to be set up prior to callin
| --- | --- | --- |
| port | <code>String</code> | The hostport for the service. Default: <code>127.0.0.1:0</code> |
| creds | <code>Object</code> | Credentials options. Default: <code>grpc.ServerCredentials.createInsecure()</code> |
| options | <code>Object</code> | The start options to be passed to `grpc.Server` constructor. |

**Example**

Expand Down
14 changes: 10 additions & 4 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,19 @@ class Mali extends Emitter {
* Start the service. All middleware and handlers have to be set up prior to calling <code>start</code>.
* @param {String} port - The hostport for the service. Default: <code>127.0.0.1:0</code>
* @param {Object} creds - Credentials options. Default: <code>grpc.ServerCredentials.createInsecure()</code>
* @param {Object} options - The start options to be passed to `grpc.Server` constructor.
* @return {Object} server - The <code>grpc.Server</code> instance
* @example
* app.start('localhost:50051')
* @example <caption>Start same app on multiple ports</caption>
* app.start('127.0.0.1:50050')
* app.start('127.0.0.1:50051')
*/
start (port, creds) {
if (_.isObject(port) && !creds) {
start (port, creds, options) {
if (_.isObject(port)) {
if (_.isObject(creds)) {
options = creds
}
creds = port
port = null
}
Expand All @@ -295,12 +299,14 @@ class Mali extends Emitter {
port = '127.0.0.1:0'
}

const server = new this.grpc.Server()
server.tryShutdownAsync = pify(server.tryShutdown)
if (!creds || !_.isObject(creds)) {
creds = this.grpc.ServerCredentials.createInsecure()
}

const server = new this.grpc.Server(options)

server.tryShutdownAsync = pify(server.tryShutdown)

_.forOwn(this.services, (s, sn) => {
const composed = {}
const methods = this.methods[sn]
Expand Down

0 comments on commit dac2c58

Please sign in to comment.