Hi community first and foremost thank for your valuable support.
I need to retrieve custom data I've written to mongoDB and I'd like them to be returned as JSON string via a custom WriteAPI-enabled route.
A few notes to give a better context:
-
I'm currently on Ubuntu 18 / nodebb 1.16.2 / Mongo DB 4.0.22 / npm 6.14.10
-
I've already read
-
I've looked at
-
and, in the end, I've created an API Access token bound to the forum administrator which works nicely to read and write in the forum (e.g. retrieving the topics or creating a new one)
Issues:
- Upon installing nodebb-plugin-friends (clone and npm link) and activating in a pristine test forum I can see the hook in
Advanced -> Hooks
but:
- why looking at the nodebb log (run as ./nodebb dev) I can't see
[plugins/friends] Write API integration enabled, routes added.
as specified here?
- assuming I'm using Postman for testing purposes how should i reach these routes? (none of these -
<url/to/nodebb>/api/v3/friends/:uid
, <url/to/nodebb>/api/friends/:uid
, <url/to/nodebb>/friends/:uid
, <url/to/nodebb>api/v3/plugins/friends/:uid
- worked for me)
- Upon creating a test plugin (see below library.js and plugin.json) I'm not able to reach any of the established new routes (as much as reported above): how can I debug the issue? Log is silent and
library.js
'use strict';
(function(routes) {
routes.initWriteRoutes = function(data, callback) {
data.router.get('/route1', data.apiMiddleware.requireUser, data.apiMiddleware.requireAdmin, middleware.verifyUserExists, function(req, res) {
console.log("/route1 reached via get");
res.sendStatus(200);
});
data.router.post('/route2', data.apiMiddleware.requireUser, middleware.verifyUserExists, function(req, res) {
console.log("/route2 reached via post");
res.sendStatus(200);
});
data.router.delete('/route3', data.apiMiddleware.requireUser, middleware.verifyUserExists, function(req, res) {
console.log("/route3 reached via delete");
res.sendStatus(200);
});
console.log('[plugins/test] Write API integration enabled, routes added.');
callback(null, data);
};
}(module.exports));
plugin.json
{
"library": "./library.js",
"hooks": [
{ "hook": "filter:plugin.write-api.routes", "method": "initWriteRoutes" }
]
}
- assuming nodebb-plugin-friends is installed why the log reports
info: [api] Adding 0 route(s) to 'api/v3/plugins'
with 0 new routes? Shouldn't it include at least the new routes coming with this plugin?
I apologise for the length of this post, but I think this might help you to steer me in the right direction.
Best, Riccardo