Customize route '/' from plugin



  • So I want to do this:

    1. If someone opens www.myhomepage.com, then he will be redirected to the forum
    2. If someone opens www.myhomepage.com?page=lol.html then he will be redirected to my custom lol.html page

    I'm aware that I can create a custom route from my plugin, but this is not what I want.

    I'm currently using the following hooks:

    "hooks": [
        {
            "hook": "static:app.load",
            "method": "init"
        },
        {
            "hook": "action:post.save",
            "method": "postSaved"
        },
        {
            "hook": "filter:post.create",
            "method": "postCreated"
        },
        {
            "hook": "filter:topic.create",
            "method": "topicCreated"
        }
    ]
    

    I tried using helpers.setupPageRoute on / but it simply doesn't work, probably because the route is being processed before the plugin routes are added.

    Is it possible to achieve what I want?



  • I guess preload hook is what I needed:

    plugin.preload = function (params, callback) {
    
        params.app.get('/', function (req, res, next) {
            if (req.query.ad) {
                res.send('Hiii')
            } else {
                next()
            }
        })
    
        callback()
    }
    

Log in to reply
 

Suggested Topics

  • 6
  • 10
  • 1
  • 1
  • 2
| |