Here you will find information about static assets you can use with Spring Cloud Gateway.
Paths used in a client app to access static assets, such as CSS or JavaScript, may not resolve when a user accesses the client app through a Spring Cloud Gateway for VMware Tanzu service instance. For example, a CSS stylesheet file path in a client app, where the path is relative to the client app context, would not be accessible if the app is being accessed through the Gateway.
To make static assets available when a user accesses a client app through the Gateway, you must add configuration in the client app. Some configuration varies depending on the template engine used in the client app. See below for information about configuring client apps using several major template engines.
Note: The information in this topic applies only to client apps based on the Spring framework.
Note: The path /scg-dashboard
is reserved for the Gateway service instance's dashboard and should not be used by a client app's static assets.
Your client app must set the Spring configuration property server.forward-headers-strategy
to framework
. For information about this property, see the Spring Boot documentation about Running Behind a Front-end Proxy Server.
In a Spring Boot application, you can set this property in the app's application.yml
file:
server:
forward-headers-strategy: FRAMEWORK
You must also use Thymeleaf context-relative URLs (see the Thymeleaf documentation about Standard URL Syntax) to reference static assets in your app.
Your client app must set the configuration property spring.freemarker.request-context-attribute
for use in static asset URLs. You must also set the server.forward-headers-strategy
property to framework
. For information about this property, see the Spring Boot documentation about Running Behind a Front-end Proxy Server.
In a Spring Boot application, you can set these properties in the app's application.yml
file:
spring:
freemarker:
request-context-attribute: rc
server:
forward-headers-strategy: FRAMEWORK
When referencing static assets in your app, use the value of the request-context-attribute
property:
<img src="${rc.getContextPath()}/images/gonzo.jpg" />
Your client app must set the configuration property spring.mustache.request-context-attribute
for use in static asset URLs. You must also set the server.forward-headers-strategy
property to framework
. For information about this property, see the Spring Boot documentation about Running Behind a Front-end Proxy Server.
In a Spring Boot application, you can set these properties in the app's application.yml
file:
spring:
mustache:
request-context-attribute: rc
server:
forward-headers-strategy: FRAMEWORK
When referencing static assets in your app, use the value of the request-context-attribute
property:
<img src="{{rc.contextPath}}/images/rizzo.jpg" />
Your client app must set the spring.groovy.template.request-context-attribute
configuration property for use in static asset URLs. You must also set the server.forward-headers-strategy
property to framework
. For information about this property, see the Spring Boot documentation about Running Behind a Front-end Proxy Server.
In a Spring Boot application, you can set these properties in the app's application.yml
file:
spring:
groovy:
template:
request-context-attribute: rc
server:
forward-headers-strategy: FRAMEWORK
When referencing static assets in your app, use the value of the request-context-attribute
property:
img(src: rc.contextPath+'/images/bean-bunny.jpg')