How to add my own API?
-
I want to add my own custom route that can take POST requests and write my own logic to provide a dynamic response.
I tried nodebb-plugin-custom-pages, but seems like that only does a GET request and only way to add content there is by ACP->/extend/widgets.
Im not advanced enough to write my own plug ins , is there a simpler way to achieve what I need?
-
@julian Thanks for the reference.
I loaded the Quickstart plugin and followed the example.
Added my route but I’m still getting “not found” when I go to http://localhost:4567/test321.plugin.addRoutes = async ({ router, middleware, helpers }) => { function render(req, res, next) { helpers.formatApiResponse(200, res); // res.send('Test') // tried this also }; router.get('/test321', render); router.get('/quickstart/:param1', middleware.authenticate, (req, res) => { helpers.formatApiResponse(200, res, { foobar: req.params.param1, }); }); };
-
@ape Take a look at my yesterday's topic.
Had similar problems, maybe the topic helps you.
routeHelpers.setupPageRoute(router, '/discord/topic/', middleware, [(req, res, next) => { winston.info(`[plugins/discord-topic] In middleware. This argument can be either a single middleware or an array of middlewares`); setImmediate(next); }], (req, res) => { winston.info(`[plugins/discord-topic] Navigated to ${nconf.get('relative_path')}/discord-topic`); render(req, res); // replace this with res.render('templateName'); });
Copyright © 2024 NodeBB | Contributors