Skip to content

Commit

Permalink
Merge pull request #395 from Frachtwerk/394-revert-changes-to-staticr…
Browse files Browse the repository at this point in the history
…esourceconfig

Revert "107 remove default success controller (#328)"
  • Loading branch information
mrAtFW authored Apr 9, 2024
2 parents 9984c1e + 96c43b9 commit c073914
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Version `___`
## Version `2.5.14`

- revert `The FallbackResourceResolver has been removed. URL paths that do not exist are no longer responded to with a DefaultSuccessPage.`
- upgraded com.nulab-inc:zxcvbn from 1.8.2 to 1.9.0

## Version `2.5.13`
Expand Down
2 changes: 1 addition & 1 deletion essencium-backend-development/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>de.frachtwerk</groupId>
<artifactId>essencium-backend-development</artifactId>
<version>2.5.13</version>
<version>2.5.14</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Essencium-backend-development represents a sample project for development purposes based on Essencium
Expand Down
2 changes: 1 addition & 1 deletion essencium-backend-identity-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>de.frachtwerk</groupId>
<artifactId>essencium-backend-identity-model</artifactId>
<version>2.5.13</version>
<version>2.5.14</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Essencium-backend-identity-model is a software library built on top of Essencium Backend that allows
Expand Down
2 changes: 1 addition & 1 deletion essencium-backend-sequence-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>de.frachtwerk</groupId>
<artifactId>essencium-backend-sequence-model</artifactId>
<version>2.5.13</version>
<version>2.5.14</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Essencium-backend-sequence-model is a software library built on top of Essencium Backend that allows
Expand Down
2 changes: 1 addition & 1 deletion essencium-backend-uuid-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>de.frachtwerk</groupId>
<artifactId>essencium-backend-uuid-model</artifactId>
<version>2.5.13</version>
<version>2.5.14</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Essencium-backend-uuid-model is a software library built on top of Essencium Backend that allows
Expand Down
2 changes: 1 addition & 1 deletion essencium-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>de.frachtwerk</groupId>
<artifactId>essencium-backend</artifactId>
<version>2.5.13</version>
<version>2.5.14</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Essencium Backend is a software library built on top of Spring Boot that allows developers to quickly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@

package de.frachtwerk.essencium.backend.configuration;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.ResourceResolverChain;

@Configuration
public class StaticResourceConfig implements WebMvcConfigurer {
Expand All @@ -40,6 +46,28 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/**")
.addResourceLocations(resourceProperties.getStaticLocations())
.resourceChain(true);
.resourceChain(true)
.addResolver(new FallbackResourceResolver("index.html"));
}

private static class FallbackResourceResolver extends PathResourceResolver {
private final String fallbackPath;

private FallbackResourceResolver(String fallbackPath) {
this.fallbackPath = fallbackPath;
}

@Override
public Resource resolveResource(
HttpServletRequest request,
@NotNull String requestPath,
@NotNull List<? extends Resource> locations,
@NotNull ResourceResolverChain chain) {
final Resource resolvedResource =
super.resolveResource(request, requestPath, locations, chain);
return resolvedResource != null && resolvedResource.exists()
? resolvedResource
: super.resolveResource(request, fallbackPath, locations, chain);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ void testGetExistingStatic() throws Exception {
void testRedirectNonExistingStatic() throws Exception {
mockMvc
.perform(get("/nonexisting"))
.andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON))
.andExpect(
content()
.string(
"{\"type\":\"about:blank\",\"title\":\"Not Found\",\"status\":404,\"detail\":\"No static resource nonexisting.\",\"instance\":\"/nonexisting\"}"));
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(content().string(INDEX_TEXT));
}
}

0 comments on commit c073914

Please sign in to comment.