How to create a new route for a new custom page

  • Hi!

    I'm developing a plugin that allows a user to ignore others and hide his posts in every topic. That part is done, now I want to create a new page to display the list of ignored users in the profile. I've done this:

    app.get('/user/:userslug/ignored', params.middleware.buildHeader, controllers.accounts.getIgnored);
    app.get('/api/user/:userslug/ignored', controllers.accounts.getIgnored);

    Where .getIgnored equals:

    controllers.accounts.getIgnored = function (req, res, next) {
    	if (!req.user) {
    		return helpers.notAllowed(req, res);
        /* Retrieve the ignored users from DB... */
    	res.render('account/ignored', {
    		userslug: req.params.userslug,
    		ignored: users

    Ok. Now, if I go to the URL /user/admin/ignored it displays my template and my ignored users perfectly. So far, so good. The problem comes when I try to access that new page from a link (i.e. the profile dropdown), then the redirect doesn't work. I've figured out that the problem is I defined the routing on server-side but not on client-side, so... ΒΏHow can I get that? Basing on the homepage plugin I suppose that I have to change the client routing by using the hook filter:templates.get_config and add this:

    Plugin.changeClientRouting = function (config, callback) {
    	config.custom_mapping['^user/.*/ignored'] = 'account/ignored';
    	callback(null, config);

    But it doesn't seem to work. 😞

    ΒΏAny help?

    Thank you πŸ™‚

  • Admin

    This should work, as far as I can see. Can I have a look at the repo, is it public?

    EDIT: also have a look at this route has it been updated?

  • Yes, the API call seems to retrieve both routes:

        "availableTemplates": [
        "templatesConfig": {
            "custom_mapping": {
                "^user/.*/ignored": "account/ignored"
            "force_refresh": {
                "logout": true

    Here is the public repo:

    If it helps, when the redirection fails, the template displays something like this:

    Captura de pantalla 2015-01-08 a las 23.45.53.png

    (Like you can see at the picture, it loads the profile view -broken- instead the new ignored view)

  • Admin

    Looks like there was a bug in core specifically for adding routes to user/xxx/route

    Update to latest or this commit for the fix πŸ™‚

  • @psychobunny said:

    Looks like there was a bug in core specifically for adding routes to user/xxx/route

    Update to latest or this commit for the fix πŸ™‚

    Thank you, I'll try πŸ˜‰

    Edit: It worked πŸ™‚

  • Hi again. A question related: Is it possible to obtain all the same data retrieved by the calls 'getFollow', 'getFollowers', etc. ? I mean all this attributes:

    userData.uid = userData.uid;
    userData.yourid = callerUID;
    userData.theirid = userData.uid;
    userData.isSelf = self;
    userData.showSettings = self || isAdmin;
    userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
    userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
    userData['email:confirmed'] = !!parseInt(userData['email:confirmed'], 10);
    userData.profile_links = results.profile_links;
    userData.status = websockets.isUserOnline(userData.uid) ? (userData.status || 'online') : 'offline';
    userData.banned = parseInt(userData.banned, 10) === 1;
    userData.websiteName ='http://', '').replace('https://', '');
    userData.followingCount = results.followStats.followingCount;
    userData.followerCount = results.followStats.followerCount;

    Those calls use the method getUserDataByUserSlug from accounts.js but I can't, because it is a private method.

    I need it to make a seamless integration of my plugin and be able to show the same dropdown menu that the other sections of the profile show. That includes the 'profile_links' for example.



Looks like your connection to NodeBB was lost, please wait while we try to reconnect.