Skip to content

Commit

Permalink
fix: allow plugins to register put handlers for specific sources
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored and tkurki committed Mar 6, 2020
1 parent 07d5d89 commit bc3d4fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SERVERPLUGINS.md
Expand Up @@ -579,7 +579,7 @@ Example use:
var myFile = require('path').join(app.getDataDirPath(), 'somefile.ext')
```
### `app.registerPutHandler(context, path, source, callback)`
### `app.registerPutHandler(context, path, callback, source)`
If a plugin wants to respond to [`PUT`](http://signalk.org/specification/1.3.0/doc/put.html) requests for a specific path, it can register an action handler.
Expand Down
10 changes: 6 additions & 4 deletions src/interfaces/plugins.ts
Expand Up @@ -93,12 +93,14 @@ export interface ServerAPI {
registerPutHandler: (
context: string,
path: string,
callback: () => void
callback: () => void,
source: string
) => void
registerActionHandler: (
context: string,
path: string,
callback: () => void
callback: () => void,
source: string
) => void
registerHistoryProvider: (provider: {
hasAnydata: (options: object, cb: (hasResults: boolean) => void) => void
Expand Down Expand Up @@ -461,9 +463,9 @@ module.exports = (theApp: any) => {
}
appCopy.getDataDirPath = () => dirForPluginId(plugin.id)

appCopy.registerPutHandler = (context, aPath, callback) => {
appCopy.registerPutHandler = (context, aPath, callback, source) => {
onStopHandlers[plugin.id].push(
app.registerActionHandler(context, aPath, plugin.id, callback)
app.registerActionHandler(context, aPath, source || plugin.id, callback)
)
}
appCopy.registerActionHandler = appCopy.registerPutHandler
Expand Down
2 changes: 1 addition & 1 deletion src/put.js
Expand Up @@ -184,7 +184,7 @@ function putPath(app, context, path, body, req, requestId, updateCb) {
}

function registerActionHandler(context, path, source, callback) {
debug(`registered action handler for ${context} ${path}`)
debug(`registered action handler for ${context} ${path} ${source}`)

if (_.isUndefined(actionHandlers[context])) {
actionHandlers[context] = {}
Expand Down

0 comments on commit bc3d4fc

Please sign in to comment.