Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/main/java/org/frankframework/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.servlet.function.RequestPredicate;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerResponse;

import static org.springframework.web.servlet.function.RequestPredicates.path;
import static org.springframework.web.servlet.function.RequestPredicates.pathExtension;
import static org.springframework.web.servlet.function.RouterFunctions.route;

@SpringBootApplication
public class Application {
Expand All @@ -11,9 +20,21 @@ public static void main(String[] args) {
app.run(args);
}



public static SpringApplication configureApplication() {
return new SpringApplication(Application.class);
}

/**
* This is a custom router function to accommodate to our single page application that we serve from this spring boot backend as well.
* This RouterFunction will make sure that we serve `frontend/index.html` whenever the path does not start with `/api/`, is not `/error` and does
* not have a path extension (to exclude static resources).
*
* @see <a href="https://github.com/spring-projects/spring-framework/issues/27257">Spring framework issue 27257</a> for more details.
*/
@Bean
RouterFunction<ServerResponse> spaRouter() {
ClassPathResource index = new ClassPathResource("frontend/index.html");
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extension -> !extension.isBlank())).negate();
return route().resource(spaPredicate, index).build();
}
}

This file was deleted.