I am trying to make a proxy server that loads external websites under my domain. My goal with this is to let people visit myDomain.com/anyDomain.com and be able to use anyDomain.com with added functionality (injected JS).
I tried using the Request package to get the html of the site and then send it to the response in Express, but this approach messes up the site (relative paths, missing CSS, bad JS requests, etc).
Is there any node package that accomplishes this task? If not, how can I do it myself?
Thank you!
This is probably not legal, so disclaimer: DONT USE THIS CODE.
The following is a very hacky example of how you could do this by using cookies to track the proxied host for any relative urls.
Basically anytime the url path matches
/*.com/*
we set run regex on it and set a cookieproxy_host
to just whatever matches*.com
. If the url path does not match that, we check if the cookieproxy_host
has been set. If it does, we tack the url path onto the cookieproxy_host
and proxy that url.