2

I want to config zuul to route request to root / to a home page. I tried:

root:
  path: /
  url: http://hostname/home/index.jsp

and

root:
  path: /**
  url: http://hostname/home/index.jsp

But neither of them works. I just got a 404 NOT FOUND. I think the path match config should be similar to those with contexts, such as /service/**, but it's not.

J Freebird
  • 3,664
  • 7
  • 46
  • 81

1 Answers1

5

This is what I have done to make this work.

Within Zuul -> controller:

@RequestMapping(value = "/", method = RequestMethod.GET)
public String handleRequest() {
    return "forward:/ux/";
}

Zuul Properties:

zuul:
  addProxyHeaders: true
  routes:
    example-ux:
      path: /ux/**
      stripPrefix: false

Within example-ux Service properties:

server:
  servlet-path: /*
  context-path: /ux

This configuration also solves the problem of static resources resolution. i.e. /static/css static/js etc...

code
  • 4,073
  • 3
  • 27
  • 47
  • Note: This is based on using Eureka for Service Discovery – code Aug 17 '16 at 01:56
  • When I did it, it just returned the string "forward:/ux/" to my browser. I think it's because there's no view named "/ux/" defined in the container. How did you define that? Also, in your second config, I suppose you missed `serviceId` or `url`? Otherwise how do you do routing. Thanks. – J Freebird Aug 17 '16 at 16:58
  • Within the example-ux service you still need either an index.html or index controller to render the ui. the `serviceId` or `url` is not required. – code Aug 22 '16 at 01:57
  • I still cannot get it work. I don't quite understand if you don't specify url or serviceId, how would zuul know the location of your example-ux service? Where would it forward the request to? – J Freebird Aug 25 '16 at 23:37
  • I have the target app, to which zuul routes, working. But `return "forward:/ux/";` in zuul still just returns me a string. I think `forward` keyword needs to work with a controller with the same name (`/ui` in this case) in zuul. – J Freebird Aug 26 '16 at 22:47
  • @ccit-spence : Its failing on static resources for me. How did you reference static resources within your ux app. did you give the full path like ux/static/js/xxxx.js or did you give it relative to the app like static/js/xxx.js – PavanSandeep May 08 '17 at 15:40
  • @PavanSandeep Not sure exactly your setup. Static in Spring Boot usually the word static is dropped. `ux/js/xxxx.js` – code May 08 '17 at 19:22
  • @ccit-spence : Understood, my point is, when you drop the client resources in the static folder of Spring boot, lets say index.html and I'm referencing /js/app.js. When it is routed through zuul, it's not adding the ux/js/app.js while routing, however, it is routing to the index page in ux app. – PavanSandeep May 09 '17 at 01:03
  • @PavanSandeep Ah, My approach was to put the static files on Zuul. – code May 09 '17 at 08:33