Question

I currently have a Spring application that can be run or debugged locally via embedded Tomcat (through spring-boot), or packaged into a war file and deployed as an app. It has some RESTful services, which are consumed by a single-page-application.

Right now, all of the static assets, including the front-end javascript, are contained in the /src/main/webapp directory. This allows rapid development of both the back-end (embedded tomcat can restart quickly for back-end changes), AND front-end code (any changes made to html/javascript/css can be picked up with just a refresh while the app is running in embedded mode).

However, for various reasons outside my control, I am going to have to separate the front-end and the back-end into separate projects which will be developed and deployed separately. This presents a problem - how do I get a local development environment setup with the same kind of rapid development of both the back-end and the front-end on the same development machine? The front-end servlet and the back-end servlet can't run on the same port, and if I set them up to use different ports, then the browser won't let the front-end javascript make requests to the back-end servlet without setting up CORS, which I'd like to avoid.

Eventually, the two apps will either be deployed to the same Tomcat instance, or else a router will route traffic to them such that they're still on the same domain, so that they can talk to each other without CORS. But that doesn't help me for local development.

Was it helpful?

Solution

I ended up using nginx: http://nginx.org/en/docs/windows.html

I added the following to my conf/nginx.conf:

    location /site1/ {
        proxy_pass http://localhost:8081/;
    }

    location /site2/ {
        proxy_pass http://localhost:8080/;
    }

And configured my two apps (site1 and site2) to run on ports 8081 and 8080 respectively. This effectively simulates the shared tomcat deployment (one domain/port) while using two running instances of tomcat embedded (on two ports).

OTHER TIPS

"The front-end servlet and the back-end servlet can't run on the same port" Yes they can, tomcat can run several servlets, indeed it can run several applications on the same instance. Just make sure the apps can be differentiated at the URL level i.e.

server.com/backend_app/
server.com/frontend_app/

Maybe I'm not understanding your question fully......

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top