【问题标题】:How to check whether my Node.js create-react-app runs on localhost?如何检查我的 Node.js create-react-app 是否在 localhost 上运行?
【发布时间】:2020-03-11 09:34:59
【问题描述】:

我尝试像这样检查,但它使应用程序崩溃:

  let fbAppId
  if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
    fbAppId = "402670860613108"
  else
    fbAppId = "2526636684068727"

我想知道应用程序何时在 Heroku 上运行以及何时在 localhost 上运行。

【问题讨论】:

  • 是在 react 还是 Node.js 中?
  • 它在 React 中,一个 create-react-app

标签: node.js heroku localhost create-react-app


【解决方案1】:

尝试通过window.location.hostname检查它,它会工作。

let fbAppId
if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1")
    fbAppId = "402670860613108"
else
    fbAppId = "2526636684068727"

【讨论】:

    猜你喜欢
    • 2019-08-01
    • 2011-06-14
    • 1970-01-01
    • 2021-02-24
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2021-12-17
    相关资源
    最近更新 更多