0

Currently using Node.js to handle all our AJAX calls, which works brilliantly but (unfortunately) still leveraging PERL to draw in-line page content, when absolutely necessary - (for instance when Facebook or some other third party site needs to call our site and read specific Meta tags that are generated by the DB) - as well as handle file uploads and stuff of that nature.

I am trying to figure out what I'd need to do to have my web server (Apache) reach out to Node.js directly, so as to replace PERL in our mix.

Would really appreciate a pointer at some documentation that explains how to set this up or (less preferably) a response saying that at present such a configuration is not possible.

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • Lots of articles come up when Googling this subject, but I understand you might not know what to search for. Basically you are looking for `mod_proxy` and using it to setup a reverse proxy: http://stackoverflow.com/questions/14259321/apache-node-js-mod-proxy-how-to-route-one-domain-to-3000-and-another-to-8 – srquinn Jan 22 '14 at 20:55
  • @jibsales, thanks! I'll follow up on that. – Yevgeny Simkin Jan 22 '14 at 21:48
  • After a lengthy search, it would appear that what I'm actually after is this: http://larsjung.de/node-cgi/ – Yevgeny Simkin Jan 22 '14 at 23:33
  • Thats definitely one way to go – I would still suggest looking into a reverse proxy setup as `node-cgi` is UGLY like PHP/Perl ;) – srquinn Jan 23 '14 at 16:43
  • @jibsales. Yep... definitely ugly. But I would never use it as anything other than a wrapper around the features currently absent from our setup. For the most part we'd continue to use Node via AJAX to populate content in static HTML pages. – Yevgeny Simkin Jan 23 '14 at 20:22
  • 1
    I like to hear "good engineering" behind problem solving like you have demonstrated here – so often on SO I hear people making decisions based on trends and "whats easy" instead of finding the right solution for the problem. – srquinn Jan 23 '14 at 20:25

2 Answers2

0

I'm rather confused by most of your question - my interpretation is that you have some URLs which you want to handle with node.js and some that you want to handle with Apache+Perl

The simplest solution is to make the 2 servers available at different URLs, e.g.

http://www.example.com:80 for the node.js

and

http://www.example.com:81 for the apache + perl

Alternatively you could use one of the servers as a proxy for the other, given a particular prefix in the path. Which way around you put the servers has a lot of implications for the performance profile of the system - but the safest solution is to use node.js at the frontend. It should be straightforward to implement this (although I'm not an expert on node.js). It's also quite possible to this the other way around - with Apache at the front using mod_rewrite (and optionally mod_proxy if you want caching):

RewriteEngine  on
RewriteRule    ^ajax/(.*)$  http://127.0.0.1:82/$1  [P]

(you'll need mod_proxy and a proxyPassReverse rule to clean up any redirects returned by the node.js server)

Another approach would be to run a content director in front of both the servers - although this adds additional overheads. For example using nginx:

location /perl/ {
    proxy_pass http://127.0.0.1:81;
}
location /ajax/ {
    proxy_pass http://127.0.0.1:82;
}

If you mean that you want all requests to be handled by node.js and some of the responses are partially made up from data accessible via Apache+perl then that's a lot more complex.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • I want all my requests to be handled by Apache, which should leverage Node.js when applicable at foo.com:80 (or have some way that httpd.conf knows that foo.com/someNode.js is to be handled on port 90000 while foo.com/everythingElse is to go to 80). The idea is that when I call foo.com/cgi-bin/someFile.cgi or foo.com/someFile.php these are run as programs by their various interpreters and then their results are printed out via http. However. I'm trying to use Node in the same way... asking if that's possible. – Yevgeny Simkin Jan 22 '14 at 22:43
0

If you really love Perl like me, you may feel like this module:

npm install exec_perl

see: https://github.com/tlqtangok/exec_perl

tlqtangok
  • 63
  • 1
  • 5