Search code examples
node.jsurlexpressrootsails.js

How to get the base or root url in sailsjs?


Is there a sails way of extracting the root or base url of an app? I basically need this for sending activation emails with links.


Solution

  • Sails.js is based on Express, so from within your action you can do the following:

    var protocol = req.connection.encrypted?'https':'http';
    var baseUrl = protocol + '://' + req.headers.host + '/';