is there a non-traumatic way to approach this: http-proxy + a static file server target

104 views
Skip to first unread message

ming

unread,
Feb 7, 2014, 12:24:31 AM2/7/14
to nod...@googlegroups.com
Hi,
A few days back we received vendor FOO's documentation in electronic format and we put the document root at
   /path/to/vendor/FOO/doc/root

With node-static and the usual:
   var static = require('node-static');
   var file = new static.Server('/path/to/vendor/FOO/doc/root');
   ...
we quickly managed to serve the documentation up via node-static in no time.

i've also been running a reverse proxy with http-proxy which requires client-side X.509 authentication.   Now i'm asked to explore the possibility to serve the vendor documentation through my reverse proxy and the URL proposed to arrive at the document root of FOO is something like:
   https://proxyHost:proxyPort/vendor/FOO

With node-static and node-proxy in the picture, i can't think of an easy way to achieve that unless i add the path prefix "/vendor/FOO" to all the paths in the files in
   /path/to/vendor/FOO/doc/root
which is quite traumatic.   Is there a better (hopefully much better) and less fragile way to achieve that?

Thanks.

Alex Kocharin

unread,
Feb 7, 2014, 12:38:24 AM2/7/14
to nod...@googlegroups.com
 
If your vendor documentation uses relative links, it should work as is. But I guess it's not the case.
 
I'd suggest to place it on a subdomain instead.
 
 
07.02.2014, 09:24, "ming" <hseu...@gmail.com>:
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sam IT

unread,
Feb 7, 2014, 9:23:42 AM2/7/14
to nod...@googlegroups.com
Here are some options, sorted by, in my opinion, the more viable and easy solutions first:

1. Use subdomains, as Alex proposed
No modification to the source files, which means it could be easily updated when you vendor updates it.

2. Add an HTML "base" element to the "head" element of all HTML files
You'll need to apply this method to all HTML files, you can create a simple middleware to get the job done.

3. Re-write all URLs
If all urls are not relative and start with a known string, you can simply create a middleware to rewrite the prefix of those URLs.
It does mean you may have to apply such a middleware to not only the HTML files, but to CSS, JS and other assets. (probably all non-binary files.)

Finally, if you're going to create a middleware to accomplish #2 or #3, you'll need to create a Transform stream and use either string replacement or a DOM/HTML/XML parser to manipulate the content.

Some packages I use that could be helpful to you:
* Stream helpers: through or through2 are very simple and useful
* HTML/DOM helper: cheerio is very simple and useful as well. If you know jQuery, you'll be all set :-)

Hseu-Ming Chen

unread,
Feb 10, 2014, 12:15:10 AM2/10/14
to nod...@googlegroups.com
Hi Alex, Sam,
Thank you for your input.


> If your vendor documentation uses relative links, it should work as is.

i don't think so due to the additional URL path "/vendor/FOO" introduced at the proxy as in:
       https://proxyHostFQDN:proxyPort/vendor/FOO
When the routing proxy passes the usual "req.url" to the target, the prefix "/vendor/FOO" is present.

> 1. Use subdomains, as Alex proposed

Yes, this will be a clean (thus preferred) solution.   However, due to Big-IP failover and load-balancing, the group in charge of that dictates the URL be in the format of
     https://proxyHostFQDN:proxyPort/vendor/FOO
and that is out of my control, :-(
 
i ended up resorting to a quick and hackish workaround: the original document root is at the file system path:
     /path/to/vendor/FOO/doc/root/...
i introduced 2 more directories in the middle as in:
     /path/to/vendor/FOO/doc/root/vendor/FOO/...

When the proxy server passes on the req.url, "/vendor/FOO", it gets absorbed by the target static file server and it has worked nicely since.

Effectively i pushed the real content 2 levels down in the file system hierarchy.    It appears that all vendor documentations use relative links so the scheme works without a hitch.    i also tested the same "hack" on the documentations for ElasticSearch_head and Kibana (both for ElasticSearch cluster) and it also works smoothly.

Thanks again.


You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/2sLl4_7xahs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages