Clean way to provide alias for link
-
Hi.
I'm writing (still!) a big plugin. I need to use my own url for some categories, but for the sake of maintaining the plugins, I operate their rendering on the normal category view (I simply modify the template by adding a few ifs and adding additional data). This looks like the best way in terms of future updates and bug resistance (so as not to duplicate all the data that NodeBB normally provides for the view).
Getting to the point. I would like to use the address in the form /my_name/:my_param but render page from /category/:cid. I can just find myself mapping between my_param to cid, but I'm searching the best, clean way to do this.
Is this possible in NodeBB without hacking hacks?
The best solution would be to simply call the function with the new URL in some hook, but I understand that it may not be that simple. -
So you want to do something like below?
app.get('/my_name/:my_param', async (req, res, next) => { const dataForCategory = await getSameDataCoreUsesForCategoryPage(req, res); res.render('category', dataForCategory); });
Right now our category controller doesn't allow calling it like that. When it is called it renders the template with the data. But we can add a new method there that does everything except rendering it and it can be used from plugins to load the same data.
-
Yes, I was thinking about this type of solution or something like this:
app.get('/my_name/:my_param', async (req, res, next) => { const cid = ... //some calls res.render("/category/"+cid"); });
And just do extra steps (add extra data) in filter:<template>.build hook.
If it is not possible now, thank you for the information, it saved me a lot of time searching for a workaround, doomed to failure.
Of course, it would be good to enable something like this in the future, but this is a second or even third category of importance from my point of view - I can always use an existing address in my case. It will be a little less fancy but still functional.EDIT:
I found not listed in hook auto-generated list hook response:router.page. Its looks like good but strange animal. I found it when I'm try to check filter:router.page - it is present in docs but is deprecated.['filter:router.page', { new: 'response:router.page', since: 'v1.15.3', until: 'v2.1.0', }],
-
Yeah that hook is deprecated you can use
response:router.page
instead. https://github.com/NodeBB/NodeBB/blob/master/src/middleware/index.js#L98It allows plugins to intercept requests and do custom redirects or render a different page etc.
-
Ok, looks like I know what I need to know, what's possible, what doesn't make sense, and what could be a workaround.
Thank you very much.