c# - Coming from AOP based authentication in ASP.MVC to nodeJS -
when in .net world , using mvc common pattern used when wanting cross cutting concerns such logging, authentication, transaction management etc use di paired aop put attributes on methods required proxying/weaving.
so may like:
public class somecontroller { [authenticate] public actionresult someauthenticatedaction() {} public actionresult notauthenticatedaction() {} }
so given above when someauthenticatedaction called check request authorization cookie logic around , either bomb user out 401 or something. know because has attribute on @ runtime knows hook , proxy.
now in javascript land , looking @ getting same sort of functionality doing best way platform. wondering how should go doing in nodejs, there no sort of attribute paradigm in javascript without either ingraining authentication each app.* (get,post etc)
call dont like, or @ application entry point proxy each action know needs authenticated, not ideal either.
so there way me indicate method should have cross cutting concern applied it, without putting logic in there? way web code doesnt know authentication mechanism, , app entry point doesnt know specific method, knows wants methods have meta-data them?
i hope makes sense, if dont use aop think im talking in riddles, doing this way makes code lot easier test , maintain , allows me re-configure applications quickly.
so far have found hooker, can proxying part of puzzle although not quite sure how underlying request object in it, wouldnt see proxying of object in js being of pain, need find way identify methods intercept... info great.
== edit ==
after reading bit more may should doing using middleware layers need, @ least allow simpler code , intentions of routes clearer. keep looking @ come once find out more or better answer appears.
as there has been no answers mention have done, made class contains logic needs carried out on route, made function exported middleware entry point. way can unit test logic , use middleware inject "concern" route.
Comments
Post a Comment