Skip to content

Commit a2ae31f

Browse files
committed
Allow CORS
1 parent 5eeb03d commit a2ae31f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.myapp.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7+
8+
@Configuration
9+
@EnableWebMvc
10+
public class CORSConfig extends WebMvcConfigurerAdapter {
11+
@Override
12+
public void addCorsMappings(CorsRegistry registry) {
13+
registry.addMapping("/api/**")
14+
.allowedOrigins("*")
15+
.allowedMethods("DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT")
16+
.allowedHeaders("x-auth-token")
17+
.exposedHeaders("x-auth-token")
18+
.maxAge(3600);
19+
}
20+
}

0 commit comments

Comments
 (0)