Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 获取完整路由url expressJs_Node.js_Express - Fatal编程技术网

Node.js 获取完整路由url expressJs

Node.js 获取完整路由url expressJs,node.js,express,Node.js,Express,我想在express js中获取路由的URL http://localhost:9310/api/arsys/v1/entry/SimpleForm5/?fields=Request ID,Assigned To,Status,Submitter,Create Date&q=Status=New&offset=5&sort=Create Date.desc 我只想要http://localhost:9310/api/arsys/v1/entry/SimpleForm5/

我想在express js中获取路由的URL

http://localhost:9310/api/arsys/v1/entry/SimpleForm5/?fields=Request ID,Assigned To,Status,Submitter,Create Date&q=Status=New&offset=5&sort=Create Date.desc
我只想要
http://localhost:9310/api/arsys/v1/entry/SimpleForm5/

我尝试了
consturl=req.protocol+':/“+req.headers.host+req.url给出
http://localhost:9310/SimpleForm5/?fields=Request%20ID,分配给%20,状态,提交人,创建%20日期&q=状态=新建&offset=5&sort=创建%20日期。desc

但它没有给出
/api/arsys/v1/entry/
。此外,我不希望在输出中使用查询参数


请帮助

在没有查询参数的情况下检索url。但是,对于主机originalUrl,您可以这样做:

const urlWithoutQueryParams = req.protocol + '://' + req.headers.host + url.parse(req.originalUrl).pathname;
例如,考虑以下代码:

router.route('/arsys/v1/entry/SimpleForm5/')
  .get(async (req, res) => {
    try {
      console.log(req.protocol + '://' + req.headers.host + url.parse(req.originalUrl).pathname)
      return res.status(200).send({ message: "OK" });
    } catch (error) {
      return res.status(500).send({ message: "Failure" });
    }
  });

app.use('/api', router);

app.listen(8080, () => {
  log.info('app started')
})
当您发送
GET
到:

http://localhost:8080/api/arsys/v1/entry/SimpleForm5/?fields=Request ID,Assigned To,Status,Submitter,Create Date&q=Status=New&offset=5&sort=Create Date.desc
结果是:

http://localhost:8080/api/arsys/v1/entry/SimpleForm5/

您想要的
req.path
是否可能重复?