admin管理员组文章数量:1023102
Is there any way to add metadata to the routes in express? for example:
app.get("/some/route", function(req,res) {
// ...
}, { some: 'meta-data' });
I am looking at a sort of AOP approach to my node application so I want to proxy certain routes with authentication and/or logging. To do this I need to be able to assign some sort of hooking identifier to each route to indicate it should be proxied, so the AOP knows nothing about the individual methods and the methods know nothing about the AOP framework...
Then without getting too much off topic I would use something like hooker or some other proxying library to check through all routes where it has some
and add a thing
interceptor.
So anyway any best practice way to do the sort of thing mentioned above?
Is there any way to add metadata to the routes in express? for example:
app.get("/some/route", function(req,res) {
// ...
}, { some: 'meta-data' });
I am looking at a sort of AOP approach to my node application so I want to proxy certain routes with authentication and/or logging. To do this I need to be able to assign some sort of hooking identifier to each route to indicate it should be proxied, so the AOP knows nothing about the individual methods and the methods know nothing about the AOP framework...
Then without getting too much off topic I would use something like hooker or some other proxying library to check through all routes where it has some
and add a thing
interceptor.
So anyway any best practice way to do the sort of thing mentioned above?
Share Improve this question edited May 13, 2023 at 7:33 Soviut 91.9k53 gold badges209 silver badges283 bronze badges asked Aug 2, 2013 at 10:03 GrofitGrofit 18.5k25 gold badges103 silver badges187 bronze badges1 Answer
Reset to default 6You almost have it. You can use the bind method to bind variables to a function call.
app.get("/some/route", function(req,res) {
res.send(this.test);
}.bind({test:'<html><body>hello world</body></html>'}));
Is there any way to add metadata to the routes in express? for example:
app.get("/some/route", function(req,res) {
// ...
}, { some: 'meta-data' });
I am looking at a sort of AOP approach to my node application so I want to proxy certain routes with authentication and/or logging. To do this I need to be able to assign some sort of hooking identifier to each route to indicate it should be proxied, so the AOP knows nothing about the individual methods and the methods know nothing about the AOP framework...
Then without getting too much off topic I would use something like hooker or some other proxying library to check through all routes where it has some
and add a thing
interceptor.
So anyway any best practice way to do the sort of thing mentioned above?
Is there any way to add metadata to the routes in express? for example:
app.get("/some/route", function(req,res) {
// ...
}, { some: 'meta-data' });
I am looking at a sort of AOP approach to my node application so I want to proxy certain routes with authentication and/or logging. To do this I need to be able to assign some sort of hooking identifier to each route to indicate it should be proxied, so the AOP knows nothing about the individual methods and the methods know nothing about the AOP framework...
Then without getting too much off topic I would use something like hooker or some other proxying library to check through all routes where it has some
and add a thing
interceptor.
So anyway any best practice way to do the sort of thing mentioned above?
Share Improve this question edited May 13, 2023 at 7:33 Soviut 91.9k53 gold badges209 silver badges283 bronze badges asked Aug 2, 2013 at 10:03 GrofitGrofit 18.5k25 gold badges103 silver badges187 bronze badges1 Answer
Reset to default 6You almost have it. You can use the bind method to bind variables to a function call.
app.get("/some/route", function(req,res) {
res.send(this.test);
}.bind({test:'<html><body>hello world</body></html>'}));
本文标签: javascriptAdding metadata to express routesStack Overflow
版权声明:本文标题:javascript - Adding metadata to express routes - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745579287a2157213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论