给定控制器功能或路径路径,如何在Express JS中获取完整的路由URL?

时间:2018-05-10 12:38:26

标签: express routing express-router

我正在编写一个Express JS应用程序,我需要计算一个给定控制器功能或路径路径的路径。

例如:

02E30E6BE24BF1EA

或者,给定参数,它可以填写URL参数,例如:

let myUrl = functionToGetRoutePath(ThingsController.getThing); // would return https://host/api/v1/things/{id}

// Or

let myUrl = functionToGetRoutePath('/things/{id}'); // would return https://host/api/v1/things/{id}

来自.NET,使用UrlHelper非常容易:

let myUrl = functionToGetRoutePath(ThingsController.getThing, { id: 1 }); // would return https://host/api/v1/things/1 // Or let myUrl = functionToGetRoutePath('/things/{id}', { id: 1 }); // would return https://host/api/v1/things/1

1 个答案:

答案 0 :(得分:0)

req.originalUrl在这方面有帮助吗?