Skip to content

Commit

Permalink
fix: adjust Cors configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveScott99 committed Feb 11, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent a29fd64 commit f359e01
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ target/
/target/maven-status/
/target/surefire-reports/
/target/test-classes/
/target/

### STS ###
.apt_generated
22 changes: 22 additions & 0 deletions src/main/java/com/daverj/account/config/CorsConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.daverj.account.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class CorsConfiguration implements WebMvcConfigurer {

@Value("${cors.origins}")
private String corsOrigins;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(corsOrigins)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE", "CONNECT");
}
}
5 changes: 4 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -31,4 +31,7 @@ keycloak:
domain: ${KEYCLOAK_DOMAIN:localhost:8080}
realm: ${REALM:astroflix-realm}
username: ${KEYCLOAK_ADMIN_USERNAME:astroflix_admin}
password: ${KEYCLOAK_ADMIN_PASSWORD:astroflix@admin}
password: ${KEYCLOAK_ADMIN_PASSWORD:astroflix@admin}

cors:
origins: ${CORS_ORIGINS:http://localhost:3000}
Binary file removed target/account-1.1-a.jar
Binary file not shown.
Binary file removed target/account-1.1-a.jar.original
Binary file not shown.

0 comments on commit f359e01

Please sign in to comment.