【问题标题】:How to get appended URL value? (e.g. localhost:3000/URL)如何获取附加的 URL 值? (例如 localhost:3000/URL)
【发布时间】:2021-03-12 00:42:19
【问题描述】:

我正在尝试使用其他 URL 作为我的应用中的数据。

例如,如果我访问localhost:3000/https://www.google.com/robots.txt

然后我想将https://www.google.com/robots.txt 作为参数,以便我可以使用它。

我尝试了以下方法,但仅在尾随值没有斜杠时才有效。

app.get('/:id', function (req, res) {
  res.send(req.params)
})

有没有可能获取附加 URL 的方法?

【问题讨论】:

标签: javascript node.js express url


【解决方案1】:

您可以使用/*获取参数然后获取索引0以获取确切的URL

app.get('/*', function(req, res) {
  var url = req.params[0];
  res.send(url);
});

【讨论】:

猜你喜欢
  • 2020-09-05
  • 2019-09-11
  • 2017-10-17
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多