如何在meanjs中获取基本网址?(How to get base url in meanjs?)
我目前很困惑,我如何获得meanjs中的基本URL并且有任何方法获得基于路由的url,这个想法起源于具有所有类似功能的框架php。 非常感谢你
i am confuse currently, how i get base url in meanjs and have any method get url base on route, this idea is originated in framework php that have all similar function. Thank you very much
最满意答案
您可以尝试使用此代码:
var url = require('url') ; app.use(function (req, res) { var hostname = req.headers.host; // hostname = 'localhost:12345' var pathname = url.parse(req.url).pathname; // pathname = '/app' console.log('http://' + hostname + pathname); })或者使用var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
在这里参考
You can try use this code:
var url = require('url') ; app.use(function (req, res) { var hostname = req.headers.host; // hostname = 'localhost:12345' var pathname = url.parse(req.url).pathname; // pathname = '/app' console.log('http://' + hostname + pathname); })Or use var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
Refference here
更多推荐
发布评论