Skip to content

Commit f707ea8

Browse files
annazarubinaphp-coder
authored andcommitted
refactor: introduce app.use-cdn property to simplify local testing.
Migration path: - application-prod.properties: add "app.use-cdn: true" property Fix #1059
1 parent 287f416 commit f707ea8

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

src/main/java/ru/mystamps/web/support/spring/boot/ThymeleafViewResolverInitializingBean.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public void afterPropertiesSet() throws Exception {
7373
}
7474

7575
boolean productionEnv = environment.acceptsProfiles("prod");
76-
viewResolver.setStaticVariables(resourcesAsMap(productionEnv));
76+
boolean useCdn = environment.getProperty("app.use-cdn", Boolean.class, Boolean.TRUE);
77+
viewResolver.setStaticVariables(resourcesAsMap(productionEnv, useCdn));
7778
}
7879

7980
// Not all URLs are exported here but only those that are being used on views
80-
private Map<String, ?> resourcesAsMap(boolean production) {
81+
private Map<String, ?> resourcesAsMap(boolean production, boolean useCdn) {
8182
Map<String, String> map = new HashMap<>();
8283

8384
map.put("PUBLIC_URL", production ? SiteUrl.PUBLIC_URL : SiteUrl.SITE);
@@ -98,7 +99,7 @@ public void afterPropertiesSet() throws Exception {
9899
ImageUrl.exposeResourcesToView(map, resourcesHost);
99100
ResourceUrl.exposeResourcesToView(map, resourcesHost);
100101

101-
ResourceUrl.exposeWebjarResourcesToView(map, production);
102+
ResourceUrl.exposeWebjarResourcesToView(map, useCdn);
102103

103104
return map;
104105
}

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public void configure(WebSecurity web) throws Exception {
8080
@Override
8181
@SuppressWarnings({ "PMD.SignatureDeclareThrowsException", "checkstyle:linelength" })
8282
protected void configure(HttpSecurity http) throws Exception {
83-
boolean useCdn = environment.acceptsProfiles("prod");
8483
boolean useSingleHost = !environment.acceptsProfiles("prod");
84+
boolean useCdn = environment.getProperty("app.use-cdn", Boolean.class, Boolean.TRUE);
8585
boolean hasH2Console = environment.acceptsProfiles("test");
8686

8787
// @todo #226 Introduce app.use-public-hostname property

src/main/resources/application-test.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ logging.level.liquibase: WARN
4444
logging.level.org.springframework.web.servlet.handler.SimpleUrlHandlerMapping: WARN
4545
logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping: WARN
4646

47+
app.use-cdn: false
48+
4749
# Full list of autoconfiguration classes:
4850
# http://docs.spring.io/spring-boot/docs/1.5.x/reference/html/auto-configuration-classes.html
4951
spring.autoconfigure.exclude: \

src/main/resources/application-travis.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappi
4040

4141
app.upload.dir: /tmp/uploads
4242
app.preview.dir: /tmp/preview
43+
app.use-cdn: false
4344

4445
# Full list of autoconfiguration classes:
4546
# http://docs.spring.io/spring-boot/docs/1.5.x/reference/html/auto-configuration-classes.html

vagrant/provisioning/roles/mystamps-app/templates/application-prod.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ logging.level.ru.mystamps.web.support.spring.security.SessionLocaleResolverAware
3333

3434
app.upload.dir: /data/uploads
3535
app.preview.dir: /data/preview
36+
app.use-cdn: true
3637

3738
server.session.cookie.secure: true
3839

0 commit comments

Comments
 (0)