Javascript 我的服务器文件出错-无效URL:index.js
我在尝试运行服务器(index.js)时遇到以下错误: 代码块如下所示:Javascript 我的服务器文件出错-无效URL:index.js,javascript,typeerror,Javascript,Typeerror,我在尝试运行服务器(index.js)时遇到以下错误: 代码块如下所示: app.get('/:url', async function (req, res) { try { return res.status(200).json(data); } catch (ex) { console.log(ex); return res.status(500).json({ messa
app.get('/:url', async function (req, res) {
try {
return res.status(200).json(data);
} catch (ex) {
console.log(ex);
return res.status(500).json({ message : "Oops." });
}
它所指的具体代码行是:
const site = await .open(decodeURIComponent(req.params.url));
以前是否有人遇到过此错误,并且知道如何在这种情况下修复它?不确定它是如何为我的整个index.js服务器抛出错误的
注意:这是一个快速应用程序请求参数url的值是
index.js
web浏览器可以将index.js
扩展为绝对URL,因为它知道可以使用当前HTML文档的URL作为基本URL
您正在Node.js中运行代码。它不会在文档中运行。没有基本URL
您需要提供一个绝对URL(例如http://example.com/index.js
)你自己
也就是说,我怀疑wappalyzer可能要求您为它提供HTML文档的URL,而不是JS文件。好吧,因为我对您的用法了解不多,所以我假设您使用了类似
http://localhost/index.js
现在的问题是,wappalyzer实际上没有获得有效的url。它获取index.js而不使用任何形式的协议(http/https/ws/wss…)。这意味着它不知道该做什么,并告诉您您提供的url无效
要解决此问题,请转到
http://localhost/https%3A%2F%2Flocalhost%2Findex.js
或附加https://或类似于您的参数的内容。您认为应该使用encodeURIComponent
而不是decodeURIComponent
索引。js
仍然不是有效的URL。你为什么删除了之前的问题?@nickzoum-no,没有做任何修改。不过,谢谢!decodeURIComponent('index.js')只是'index.js',这很好。我认为wappalyzer.open()需要一个完整的url。为什么我的服务器文件需要显示在url中?它是否应该对客户端隐藏?@KirtMac99-您没有理由向客户端显示服务器端源代码,我也不建议您这样做。您需要向wappalyzer提供一个绝对URL(可能是HTML文档)。
const site = await .open(decodeURIComponent(req.params.url));