From 5e2b2e2775421cd98286d6e2f75cf38aae7a212c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Apr 2020 15:07:54 +0200 Subject: Add ability for plugins to add custom routes --- support/doc/plugins/guide.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'support/doc/plugins/guide.md') diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 8e720e94b..bdc9d2ad8 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -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 -- cgit v1.2.3