Skip to content

Commit

Permalink
Add plugin status http GET and document the HTTP api
Browse files Browse the repository at this point in the history
  • Loading branch information
tkurki committed Nov 13, 2016
1 parent 07ecbd0 commit 4368588
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions SERVERPLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ In essence a plugin is an npm module with `signalk-node-server-plugin` keyword i
The module must export a single `function(app)` that must return an object with functions `start(configuration)` and `stop` and a field `schema`. The schema value should be the structure of the plugin's configuration data as [JSON Schema](http://json-schema.org/).

See [MarineTraffic Reporter](https://github.com/tkurki/marinetrafficreporter) for an example.

##HTTP API

###`GET /plugins/`

List of installed plugins with their configuration data.

###`GET /plugins/<pluginid`

```
{
"enabled": false,
"id": "marinetrafficreporter",
"name": "Marine Traffic Reporter"
}
```

###`POST /plugins/<pluginid/configure`

Save configuration data for a plugin. Stops and starts the plugin as a side effect.
10 changes: 9 additions & 1 deletion lib/interfaces/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(app) {

router = express.Router();

app.use('/plugins', function(req, res, next) {
app.get('/plugins', function(req, res, next) {
res.json(app.plugins.map((plugin) => {
var data = null
try {
Expand Down Expand Up @@ -108,6 +108,14 @@ function registerPlugin(app, pluginName) {

var router = express.Router()
router.use(bodyParser.json())
router.get("/", (req, res) => {
const options = getPluginOptions(plugin.id)
res.json({
enabled: options.enabled,
id: plugin.id,
name: plugin.name
})
})
router.post("/config", (req, res) => {
fs.writeFile(pathForPluginId(plugin.id), JSON.stringify(req.body, null, 2), function(err) {
if (err) {
Expand Down

0 comments on commit 4368588

Please sign in to comment.