Skip to content

Commit

Permalink
Merge pull request #34 from Anyungu/dev-test
Browse files Browse the repository at this point in the history
cors
  • Loading branch information
Anyungu authored Aug 18, 2020
2 parents aa1cbd2 + 90e3a57 commit 1126fe6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mesozi.notificationservice.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class FilterConfig {

@Bean
public FilterRegistrationBean<?> corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/**", config);
FilterRegistrationBean<?> bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(0);
return bean;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1")
@RequestMapping("api/v1/noti")
public class NoticeController {

@Autowired
Expand All @@ -35,7 +35,7 @@ public Map<String, String> getAllNotice() {

}

@PostMapping(path = "notice")
@PostMapping(path = "/notice")
public Map<String, String> createNotice(@RequestBody Notice notice) {

return notificationsMap.populateMap(notice.getNoticeName(), notice.getNoticeMessage());
Expand Down

0 comments on commit 1126fe6

Please sign in to comment.