Skip to content

Commit 702c867

Browse files
committed
feat: add CORS configuration to WebConfig for API access
1 parent 59e8ef5 commit 702c867

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
package me.nayanm.blog.config;
22

3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7+
8+
@Configuration
39
public class WebConfig {
10+
11+
@Bean
12+
public WebMvcConfigurer corsConfigurer() {
13+
return new WebMvcConfigurer() {
14+
@Override
15+
public void addCorsMappings(CorsRegistry registry) {
16+
registry.addMapping("/api/**")
17+
.allowedOrigins("https://blogfrontend.z9.web.core.windows.net")
18+
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
19+
.allowedHeaders("*")
20+
.allowCredentials(true);
21+
}
22+
};
23+
}
424
}
25+

0 commit comments

Comments
 (0)