New to node.js. Need help with Node application running through Apache web server

43 views
Skip to first unread message

Kyle Hall

unread,
Nov 9, 2017, 6:07:56 PM11/9/17
to nodejs
My team and I are new to node.js and are currently working on our first project. We've run into an issue when deploying the project to our test server.

We are trying to run the application on our primary domain, which currently hosts a number of websites built in ColdFusion and Plone. We use Apache server to proxy these various sites. We are attempting to do the same with our Node application.

When we run the application directly on our test server, it works fine: e.g. http://servername:3000.

In order to view the application off our VPN, we set up an Apache proxy to our public-facing test URL: http://www.testdomain.com/calendar. The application runs, but none of our CSS or JS files show up. They are all 404ing in the debugging console, showing up as http://www.testdomain.com/css/layout.css instead of http://www.testdomain.com/calendar/css/layout.css.

We've found that if we add /calendar to the CSS and JS paths in the layout.jade file, it works. But we're wondering if there is a way to set up our Apache proxy so that it only proxies the front-end pages and not the internal CSS and JS folders. The other problem is that we also have JS files at the root of our application, so we would likely have to proxy ignore those files individually as well.

We attempted to use connect-modrewrite to fix the issue, but that just caused us more problems.

Any help would be appreciated. Thanks!

Zlatko

unread,
Nov 14, 2017, 12:58:39 PM11/14/17
to nodejs
Hi,


On Friday, November 10, 2017 at 12:07:56 AM UTC+1, Kyle Hall wrote:

In order to view the application off our VPN, we set up an Apache proxy to our public-facing test URL: http://www.testdomain.com/calendar. The application runs, but none of our CSS or JS files show up. They are all 404ing in the debugging console, showing up as http://www.testdomain.com/css/layout.css instead of http://www.testdomain.com/calendar/css/layout.css.

We've found that if we add /calendar to the CSS and JS paths in the layout.jade file, it works. But we're wondering if there is a way to set up our Apache proxy so that it only proxies the front-end pages and not the internal CSS and JS folders. The other problem is that we also have JS files at the root of our application, so we would likely have to proxy ignore those files individually as well.
 
Well, there are a few things. One, you would be much better off if you serve the assets directly by apache. Say your static stuff is in your /var/app/public/assets/{css/img/js} directory - you would tell your proxy (in this case apache) to serve any of the /calendar/assets/* requests directly from there. That way you offload serving static files from your app server (Node).

The other thing is to setup static route differently - e.g. you probably have somewhere in your code a line like this: app.use('/assets', express.static(__dirname + '/public/assets')); Now, what you do there is say app.use('/calendar/assets', express.static(...));. The first solution is much better because your node app will always work on / path if served standalone (like when you're working on the app), and your proxy can pick and choose on which virtual directory you serve from (e.g. if you want to change /calendar to /cal, or even serve from both, your app developers don't need to know about this at all, the ops guy sets it up as he wants it).

 
Reply all
Reply to author
Forward
0 new messages