Hack Forums
[Javascript] Can we write middle-ware/modules for other technologies? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [Javascript] Can we write middle-ware/modules for other technologies? (/showthread.php?tid=5698128)



Can we write middle-ware/modules for other technologies? - severos - Aug 18, 2017

I was wondering, is it possible to write some middle-ware/modules using Node.JS and then use them with other technologies?
As a useless example (just for demo idea), writing a Node.JS module that handles CORS headers, all it does is add the headers for CORS based on a config (regardless of its origin). And then, deploy this module to use with other technologies, for example use it with PHP, ASP.NET, etc.
The idea I could think of is something like registering modules in IIS (in theory), but I have no idea how to do that (for IIS or other hosting environments).

Is it possible to make such a thing? if so, how would I do it??


* - doon - Aug 19, 2017

(Aug 18, 2017 11:41 PM)severos Wrote:  I was wondering, is it possible to write some middle-ware/modules using Node.JS and then use them with other technologies?
As a useless example (just for demo idea), writing a Node.JS module that handles CORS headers, all it does is add the headers for CORS based on a config (regardless of its origin). And then, deploy this module to use with other technologies, for example use it with PHP, ASP.NET, etc.
The idea I could think of is something like registering modules in IIS (in theory), but I have no idea how to do that (for IIS or other hosting environments).

Is it possible to make such a thing? if so, how would I do it??

Sounds more like just you want to use Node as a micro service or API.


* - severos - Aug 19, 2017

(Aug 19, 2017 12:28 AM)Recollect. Wrote:  Sounds more like just you want to use Node as a micro service or API.

Not really in that meaning, far as I understand a micro service is a stand alone, it does all the work to process a request (receive, generate response, send), while I'm looking to manipulate the request, another example would be using node.js to verify session and authentication of a request before passing it to ASP.NET handler, that way the ASP.NET application wouldn't need to do any auth stuff, just focus on its work.


* - D3xus - Aug 19, 2017

I can imagine you could do so if you were using it with a REST API, or in some context where the technology involved didn't matter, and all you cared about was an output. Though it's probably easier to implement such a middleware in whatever API you might create, rather than needing a Node module to do so (unless you have a strong reason for doing so.)

For example, you might have a Python application that calls a REST API. But before it does that, you send it to some Node application (as a proxy, relay, cloak, whatever). The Node application can do its thing, and return either the result of the API if the middleware passes, or return an error if the middleware fails.


* - severos - Aug 19, 2017

I know it's possible to make it as a separate API, but then it won't have access to the original request to modify it.