0

Prerequisites

  • spring-boot 1.3.1.RELEASE
  • TypeScript 1.8.9
  • AngularJs 1.5.3
  • Zuul

I have an api gateway which hides a set of microservices. This api gateway uses zuul to map Urls to the different microservices.

zuul:
  routes:
service1:
  path: /service1/**
  serviceId: FIRST-MICROSERVICE
service2:
  path: /service2/**
  serviceId: SECOND-MICROSERVICE
service3:
  path: /service3/**
  serviceId: THIRD-MICROSERVICE

Question

I want to be able to start the api gateway on different ports with spring-boot like this:

java -jar -Dserver.port=8081 myspringbootapplication.jar

The host should always be the host from which the angularjs application was delivered. The problem is that the port depends on the port spring-boot startet the tomcat server. At the moment http://localhost:9001 is hardcoded.

    .factory('app.core.services.myApiResource', ['$resource', '$http',
        ($resource:ng.resource.IResourceService, $http:ng.IHttpService):ng.resource.IResourceClass<ng.resource.IResource<any>> => {
            var apiRoot : ng.resource.IResourceClass<ng.resource.IResource<any>>
                = $resource('http://localhost:9001/service1/myentity/search/:finderName');
            return apiRoot;
        }
    ])

In bootstrap.yml the default port is 9001

# Default ports
server.port: 9001

Is there a way to set the port value in angularjs $resource to spring-boot server.port value?

Max
  • 475
  • 1
  • 10
  • 19
  • when you bootstrap your angular application you could read the config file and set the correspondending value in the angular service http://stackoverflow.com/questions/22825706/angularjs-load-config-on-app-start – Tobias Timm Apr 22 '16 at 10:05
  • Why are you even specifying the host and port? Wouldn't `/service1/myentity/search/:findername` just work? You don't want to tie it to a specific server/port just let Angular (or actually the browser) handle that for you. – M. Deinum Apr 22 '16 at 10:20
  • @M.Deinum : Not specifying the host an port works. Thanks. – Max Apr 22 '16 at 11:23

0 Answers0