Add ability for plugins to add custom routes

This commit is contained in:
Chocobozzz
2020-04-10 15:07:54 +02:00
parent 9afa0901f1
commit 5e2b2e2775
11 changed files with 483 additions and 233 deletions

View File

@@ -12,6 +12,7 @@
- [Settings](#settings)
- [Storage](#storage)
- [Update video constants](#update-video-constants)
- [Add custom routes](#add-custom-routes)
- [Client helpers (themes & plugins)](#client-helpers-themes--plugins)
- [Plugin static route](#plugin-static-route)
- [Translate](#translate)
@@ -71,7 +72,9 @@ async function register ({
storageManager,
videoCategoryManager,
videoLicenceManager,
videoLanguageManager
videoLanguageManager,
peertubeHelpers,
getRouter
}) {
registerHook({
target: 'action:application.listening',
@@ -178,6 +181,20 @@ videoLicenceManager.addLicence(42, 'Best licence')
videoLicenceManager.deleteLicence(7) // Public domain
```
#### Add custom routes
You can create custom routes using an [express Router](https://expressjs.com/en/4x/api.html#router) for your plugin:
```js
const router = getRouter()
router.get('/ping', (req, res) => res.json({ message: 'pong' }))
```
The `ping` route can be accessed using:
* `/plugins/:pluginName/:pluginVersion/router/ping`
* Or `/plugins/:pluginName/router/ping`
### Client helpers (themes & plugins)
### Plugin static route