2

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.

Jeremy Bell
  • 5,253
  • 5
  • 41
  • 63
  • 1
    Even if they are developed by two separate people you'll want your development environment to look as much like production as possible, therefore you should still deploy them in the same development server. Assuming that you are doing the front-end, then you could get access to the latest back end from your VCS, or from a maven-like repo, or by email (it doesn't matter, really, though maven is easiest/best). You should deploy this, along with your front-end stuff, and carry on working on your bits, only updating the server side when you need to. – Software Engineer Feb 28 '14 at 22:53
  • Sounds like a great time to start using a different domain for static assets ? static.domain.com ( good cache headers, no cookies etc ) ? – Rob Sedgwick Feb 28 '14 at 23:01
  • Either way you are looking at setting up X-domain allowances in your web.xml if wanting to all look at a single server with separate 'js clients' - found a link to that - http://stackoverflow.com/questions/12383109/access-control-allow-origin-in-tomcat – Rob Sedgwick Feb 28 '14 at 23:10

2 Answers2

1

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).

Jeremy Bell
  • 5,253
  • 5
  • 41
  • 63
0

"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......

Anthony Palmer
  • 944
  • 10
  • 15
  • They can easily be the same port in a tomcat instance, but not two tomcat embedded instances, because they would no longer be in the same process. – Jeremy Bell Mar 03 '14 at 14:19