• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Use response:router.page instead of filter:router.page (deprecated)

Scheduled Pinned Locked Moved Technical Support
5 Posts 4 Posters 396 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alfazaz
    wrote on last edited by
    #1

    Hello !

    I'm upgrading my plugins and I have a problem. I get this message in my nodebb 1.15.5 logs :

    2021-01-01T17:32:47.395Z [5678/284882] - warn: [plugins/nodebb-plugin-forcelogin-YA] Hook "filter:router.page" is deprecated, please use "response:router.page" instead.
    

    so I want to change the hook I use in my plugin. I changed in plugin.json filter to response but it gives error on running after this change. How must I change the following function called by this hook ?

    plugin.YAfonction = function(req, res, next) {
    	if (!req.uid && !req.originalUrl.startsWith(nconf.get('relative_path') + '/login') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/api/login') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/api/reset') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/reset')) {
    		helpers.notAllowed(req,res);
    	} else {
    		next();
    	}
    };
    

    May be it's simple... But I'm not a great programmer...
    Thanks in advance !

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to alfazaz on last edited by
    #2

    @alfazaz looks like you need to change your function from something like

    function hook(req, res, next) { ... }
    

    To something like

    function hook(data, next) {
        var req = data.req; var res = data.res;
        ...
    }
    
    A 1 Reply Last reply
    1
  • A Offline
    A Offline
    alfazaz
    replied to PitaJ on last edited by
    #3

    @pitaj Thanks ! It worked (without next in fact).

    julianJ 1 Reply Last reply
    0
  • julianJ Online
    julianJ Online
    julian GNU/Linux
    replied to alfazaz on last edited by
    #4

    @alfazaz That's the thing about response hooks, they're awaited, and next is not checked. NodebB will check if you have sent a response to the end-user, and if you have, automatically wrap up the plugin hook call.

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    alfazaz
    replied to julian on last edited by
    #5

    @julian Yes. I saw it. Thanks !

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development