Merge pull request #434 from jkiddo/feat/fix-cors
fix: configuration of cors
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package ca.uhn.fhir.jpa.starter.annotations;
|
||||
|
||||
import ca.uhn.fhir.jpa.starter.AppProperties;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
public class OnCorsPresent implements Condition {
|
||||
@Override
|
||||
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) {
|
||||
|
||||
AppProperties config = Binder.get(conditionContext.getEnvironment()).bind("hapi.fhir", AppProperties.class).orElse(null);
|
||||
if (config == null) return false;
|
||||
if (config.getCors() == null) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
||||
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
|
||||
import ca.uhn.fhir.jpa.starter.AppProperties;
|
||||
import ca.uhn.fhir.jpa.starter.annotations.OnCorsPresent;
|
||||
import ca.uhn.fhir.jpa.starter.annotations.OnImplementationGuidesPresent;
|
||||
import ca.uhn.fhir.jpa.starter.common.validation.IRepositoryValidationInterceptorFactory;
|
||||
import ca.uhn.fhir.jpa.starter.util.EnvironmentHelper;
|
||||
@@ -214,7 +215,7 @@ public class StarterJpaConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "hapi.fhir", name = "cors")
|
||||
@Conditional(OnCorsPresent.class)
|
||||
public CorsInterceptor corsInterceptor(AppProperties appProperties) {
|
||||
// Define your CORS configuration. This is an example
|
||||
// showing a typical setup. You should customize this
|
||||
|
||||
Reference in New Issue
Block a user