3

I am setting up proxy server using NODE and EXPRESS. I have the same setup/codebase in local and proxy server. But i want to use all the js,css,images and other static content from local machine and json response from proxy server. Now since the proxy server also has same ,js,css,images, it is picking up everything from proxy. Do I need to restrict urls calls to not pick js,css,images and other static content from proxy but from local. How do i do that? Here is the code structure (both in local and proxy)

 /src
  /javacode

/WebContent
  /js
  /css
  /images
  /jsp

I want everything under /WebContent to be used from local. This is how i setup proxy:

var proxy = httpProxy.createProxyServer();

    app.route('/app/*$').all(function (req, res) { // proxy all requests

        proxy.web(req, res, {target: 'http://proxy-server:7001'}); //sandbox
    });
2
  • For the static content you want served from your local machine, can it all be served from a common path root, eg /public? Commented May 4, 2015 at 15:25
  • eah I create a public folder and put all content from /WebContent into it...will that work? By the way in this case, isn't '/WebContent' same as '/public'? Commented May 4, 2015 at 15:35

1 Answer 1

2

Given your file structure, you can use express.static to map your static /WebContent dir to a WebContent virtual path, like this:

var proxy = httpProxy.createProxyServer();

app.use('/app/js', express.static('WebContent/js'));
app.use('/app/css', express.static('WebContent/css'));
app.use('/app/etc', express.static('WebContent/etc'));

app.route('/app/*$').all(function (req, res) { // proxy all requests
    proxy.web(req, res, {target: 'http://proxy-server:7001'}); //sandbox
});
Sign up to request clarification or add additional context in comments.

7 Comments

I tried that but it still pick up static content from proxy server may be because the urls route that I have setup falls under that criteria?
Ah I think I had a mistake in my code sample. I should have been passing the dir name directly to the static method. I've updated it, give that a try.
basically my application is deployed with name 'app' and all the static content are under /WebContent which is a root folder. So when I make call, it looks for js with url '/app/js/file.js' (same for css , images or other static content) and since this url passes the route criteria ('/app/*$'), it picks the content from server and not from local
So you would like the route /app/WebContent to serve your local content?
no 'app' is the application name when it is deployed and it looks for all the resources under root fiolder which /WebContent
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.