Add web plugins functionality. #245
Open
+562
−153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
This is a proposal to make sinopia web interface extensible.
Background
I am currently using sinopia in production, and I like it a lot.
There are some things that I would like to be able to do through the web interface, for example managing users, but it seems that there is no such functionality for the moment.
I believe this is not something that should belong to the core, so it would be great to be able to plugin some functionality in the web interface.
Implementation
Extract layout from
index.hbs
so it can be sharedSet all variables needed for the layout in a middleware
Load all plugins listed in
config.web_plugins
and use them as an express middleware. Plugins should export a function called with the following parametersconfig
: Sinopia configurationlogger
: Sinopia loggerauth
: The authentication modulestorage
: The storage moduleHandlebars
: TheHandlebars
object with the registered layout (it does not seem to be possible to reuse the layout when requiring Handlebars from another file)and return an object with the following keys:
title
: The displayed title of the pluginbasePath
: The base path for the pluginmiddleware
: The express middleware for the pluginWith the above implementation, a plugin can be created with a code like this:
And will be available at
/-/users
(whereusers
is thebasePath
exported by the plugin).When present, plugins are available from the header as a dropdown menu.
This change only concerns the web interface, and does not change anything in the rest of the application nor makes anything incompatible with previous versions of sinopia.
Please tell me what you think about it.
Thanks.