Skip to content

Commit

Permalink
Adds support for trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
JREastonMarks committed Jan 26, 2024
1 parent 97917e2 commit 7adbaa5
Showing 1 changed file with 53 additions and 47 deletions.
100 changes: 53 additions & 47 deletions src/main/java/org/cbioportal/WebAppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -16,54 +17,59 @@
//@EnableAspectJAutoProxy // TODO no idea what this does; is this logging aspect still useful?
public class WebAppConfig implements WebMvcConfigurer {

private static final String SINGLE_PAGE_APP_ROOT = "forward:/";

@Value("${springdoc.swagger-ui.path:/swagger-ui.html}")
private String swaggerRedirectUrl;
private static final String SINGLE_PAGE_APP_ROOT = "forward:/";

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/webapp/images/");
registry.addResourceHandler("/reactapp/**").addResourceLocations("classpath:/reactapp/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
}
@Value("${springdoc.swagger-ui.path:/swagger-ui.html}")
private String swaggerRedirectUrl;

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/api", swaggerRedirectUrl);


// Redirects for single page app
registry.addViewController("/results/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/results**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/patient/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/patient**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/study/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/study").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/mutation_mapper/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/mutation_mapper").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/index.do/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/case.do/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/loading/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/comparison").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/comparison/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/restore").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/index.do**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/oncoprinter**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/encodedRedirect").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/datasets**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/ln**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addRedirectViewController("/installations", "https://installationmap.netlify.app/");
}

@Bean
public HandlerInterceptor involvedCancerStudyExtractorInterceptor() {
return new InvolvedCancerStudyExtractorInterceptor();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/webapp/images/");
registry.addResourceHandler("/reactapp/**").addResourceLocations("classpath:/reactapp/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/api", swaggerRedirectUrl);

// Redirects for single page app
registry.addViewController("/results/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/results**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/patient/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/patient**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/study/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/study").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/mutation_mapper/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/mutation_mapper").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/index.do/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/case.do/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/loading/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/comparison").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/comparison/*").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/restore").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/index.do**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/oncoprinter**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/encodedRedirect").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/datasets**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addViewController("/ln**").setViewName(SINGLE_PAGE_APP_ROOT);
registry.addRedirectViewController("/installations", "https://installationmap.netlify.app/");
}

@Bean
public HandlerInterceptor involvedCancerStudyExtractorInterceptor() {
return new InvolvedCancerStudyExtractorInterceptor();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(involvedCancerStudyExtractorInterceptor());
}

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Adds support for trailing slash Matches
configurer.setUseTrailingSlashMatch(true);
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(involvedCancerStudyExtractorInterceptor());
}

}

0 comments on commit 7adbaa5

Please sign in to comment.