How to get current domain address in sails.js

前端 未结 6 1489
再見小時候
再見小時候 2021-01-18 22:23

I trying to get current web address using sails.js.

I tried the following:

req.param(\'host\') and req.param(\'X-Forwarded-Protocol\') 
6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 23:11

    On sails 0.10.x, you could do this:

    //inside controller action
    var baseURL = req.protocol + '://' + req.host;
    

    req.protocol will give you 'http' or 'https' (or whatever application protocol). req.host will be the host's header, e.g. 'sub.domain.com'

    As noted in a comment above, sails.getBaseURL() or any of it's variants will usually return localhost, even in a production environment.

提交回复
热议问题