File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed 
java/com/amigoscode/config Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1+ package  com .amigoscode .config ;
2+ 
3+ import  org .springframework .beans .factory .annotation .Value ;
4+ import  org .springframework .context .annotation .Configuration ;
5+ import  org .springframework .web .servlet .config .annotation .CorsRegistration ;
6+ import  org .springframework .web .servlet .config .annotation .CorsRegistry ;
7+ import  org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
8+ 
9+ import  java .util .List ;
10+ 
11+ @ Configuration 
12+ public  class  WebMvcConfig  implements  WebMvcConfigurer  {
13+ 
14+ //    cors.allowed.origins=* 
15+     @ Value ("#{'${cors.allowed.origins}'.split(',')}" )
16+     private  List <String > allowedOrigins ;
17+ 
18+ //    cors.allowed.methods=* 
19+     @ Value ("#{'${cors.allowed.methods}'.split(',')}" )
20+     private  List <String > allowedMethods ;
21+ 
22+     @ Override 
23+     public  void  addCorsMappings (CorsRegistry  registry ) {
24+         CorsRegistration  corsRegistration  = registry .addMapping ("/api/**" );
25+         allowedOrigins .forEach (corsRegistration ::allowedOrigins );
26+         allowedMethods .forEach (corsRegistration ::allowedMethods );
27+     }
28+ }
Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ spring.jpa.hibernate.ddl-auto=validate
88spring.jpa.show-sql =true
99spring.jpa.properties.hibernate.format_sql =true
1010
11- server.error.include-message =always
11+ server.error.include-message =always
12+ 
13+ cors.allowed.origins =*
14+ cors.allowed.methods =*
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments