Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package bio.overture.score.server;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Application entry point.
Expand All @@ -20,8 +24,23 @@
})
public class ServerMain {

@Value("${management.endpoints.web.cors.allowedOrigins}")
private String[] allowedOrigins;

public static void main(String... args) {
SpringApplication.run(ServerMain.class, args);
}

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("PUT", "DELETE", "GET", "POST");
}
};
}

}
7 changes: 7 additions & 0 deletions score-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ auth:
# E.g. TIMEOUT(n) = TIMEOUT(n-1) * MULTIPLIER
multiplier: 2.0

#allowedOrigins can be configured to contain multiple values, all separated by commas
management:
endpoints:
web:
cors:
allowedOrigins: http://localhost:8081
Comment on lines +86 to +90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to include the cors settings in the server section of the yaml (line 25)?

would look like:

server:
  port: 5431
  compression:
    enabled: true
    mime-types: application/json
  cors:
    allowedOrigins:
      - http://localhost:8081
      - http://example.com


---

###############################################################################
Expand Down