Skip to content

Instantly share code, notes, and snippets.

@djazayeri
Last active July 27, 2018 22:43
Show Gist options
  • Save djazayeri/ece6862633ea50415a277164bddf469f to your computer and use it in GitHub Desktop.
Save djazayeri/ece6862633ea50415a277164bddf469f to your computer and use it in GitHub Desktop.
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Fix handling of /api/v1/addon/org.openmrs.module.appui (otherwise appui is treated as a file extension)
configurer.setUseRegisteredSuffixPatternMatch(true);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
// It's okay to make cross-origin requests to our API. For example we specifically expect that the OpenMRS OWA for
// managing modules will do this.
registry.addMapping("/**");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// Our ReactJS app is served from the root path, and we want to support using the HTML5 history API for routing
// and support deep links. But we also want to support REST controllers, e.g. at /api/**. We can't figure out a
// way to do a wildcard-except-for-api, so instead we map each individual route from the JS app here:
super.addViewControllers(registry);
registry.addViewController("/about").setViewName("forward:/index.html");
registry.addViewController("/indexingStatus").setViewName("forward:/index.html");
registry.addViewController("/search").setViewName("forward:/index.html");
registry.addViewController("/show/**").setViewName("forward:/index.html");
registry.addViewController("/lists").setViewName("forward:/index.html");
registry.addViewController("/list/**").setViewName("forward:/index.html");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment