astrolince astrolince - 11 months ago 87
Javascript Question

I get req.params.id = 'favicon.ico' when I send GET /whatever to custom route 'GET /:id'

(Sails.js)

How to ignore the favicon browser request and get the id that I want?

router.js

'GET /:id': 'UrlController.findOne'


UrlController.js

/**
* `UrlController.findOne()`
*/
findOne: function (req, res) {
var id = req.param('id');

console.log(id);

Url.findOne({where: {id: id}}).exec(function(err, url) {
return res.redirect(url.target);
})
},


Any way to simply prioritize static files before routes?

Answer Source

I found a more elegant solution:

Change:

router.js

  'GET /:id': 'UrlController.findOne'

To:

  'GET /:id': {
    controller: "UrlController",
    action: "findOne",
    skipAssets: true
  },

Also thanks to all for guiding me towards the solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download