You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+93-1Lines changed: 93 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,10 +111,102 @@ Here is the summary of existing routes at the moment:
111
111
* Post: `/news/my-post`
112
112
* Anything else: `/foo/bar`
113
113
114
+
## Extensions
115
+
116
+
The platform can be extended in the following ways:
117
+
118
+
### Theme Routes
119
+
120
+
Your theme needs a `routes.js` file which defines a `module.export` function that receives the express `app` object. Use `app` to add routes, middleware, etc, to the frontend app.
121
+
122
+
When your theme is enabled, the `routes.js` file will be parsed by the app.
123
+
124
+
*NOTE* You do not need to return anything from this function, just extend the app object by reference.
125
+
126
+
And in `/themes/your_cool_theme/routes.js`:
127
+
```
128
+
module.exports = function (app) {
129
+
// extend the express app object as you see fit
130
+
// for example, add a route /foo
131
+
app.get('/foo', (req, res) => {
132
+
res.render('example.html', {
133
+
title: 'Example Theme route',
134
+
content: {foo: 'Hello theme route'}
135
+
})
136
+
})
137
+
}
138
+
```
139
+
140
+
### Plugins
141
+
142
+
#### User Defined Plugins
143
+
144
+
Users can define plugins.
145
+
146
+
Create a directory with the plugins name in `/plugins`
147
+
Add an `index.js` file that uses the app object, as in `theme routes` above.
148
+
149
+
Add the plugin name to your `.env` file (or to your node environment via any available method). Separate multiple plugins with a space:
150
+
`PLUGINS=your_cool_plugin`
151
+
152
+
For example, we will create a `req_parameter_logger` plugin:
If an express middleware plugin is available as a standalone module on npm you can install it as-is by installing the package via npm, and adding it to your `PLUGINS` variable in `.env`
185
+
186
+
For example, we will install the cookie-parser plugin, alongside our example.
187
+
188
+
in `.env`:
189
+
`PLUGINS="example cookie-parser"`
190
+
191
+
now install the npm package:
192
+
`$ yarn add cookie-parser`
193
+
194
+
Cookie-parser will now be applied to all of your requests as express middleware!
195
+
196
+
(For instance, you could take advantage of this in custom routes, etc)
197
+
198
+
For more on express middleware: https://expressjs.com/en/guide/using-middleware.html
199
+
114
200
## Tests
115
201
116
-
Run tests (note that tests are running against mocked API_URL set to http://127.0.0.1:5000/api/3/action/):
thrownewError(`Cannot find configured plugin ${plugin}. Is it installed? If the plugin is an npm module try to run\n"yarn add ${plugin}"\nIf it is a user plugin, make sure you have a directory at ${userPluginPath} and a valid index.js file there.`)
261
+
}
262
+
})
263
+
}catch(e){
264
+
constplugins=config.get('PLUGINS').split(" ")||[]
265
+
console.warn('WARNING: Failed to load configured plugins',plugins,e)
0 commit comments