【问题标题】:Get current url hostname NODE获取当前 url 主机名 NODE
【发布时间】:2019-09-14 11:31:29
【问题描述】:

我有一个多域站点,我需要知道我的项目是在“website1.local”还是“website2.local”中运行。 我用这段代码尝试获取当前的 url,但它不起作用:

const mix = require('laravel-mix');

var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

var url = require('url');

var requrl = url.format({
   protocol: req.protocol,
   host: req.get('host'),
   pathname: req.originalUrl,
});

console.log(requrl);

返回的错误是:req is not defined

如何获取我的节点项目的当前 url?

【问题讨论】:

  • 请求应该在哪里定义?
  • @RaymondPeng 很简单,告诉我如何用Node获取当前url
  • @RaymondPeng 你可以看看下面的答案

标签: javascript node.js laravel webpack


【解决方案1】:

你可以使用:

【讨论】:

  • ReferenceError: window is not defined。 Node js 和 Webpack 中没有定义 window 对象。
猜你喜欢
  • 2012-11-05
  • 1970-01-01
  • 1970-01-01
  • 2012-03-26
  • 2011-11-22
  • 1970-01-01
  • 2021-08-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多