Skip to content

Commit

Permalink
refactor: optimize CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhi33 committed Jul 20, 2024
1 parent e78383f commit 6fa9e3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.xuanzhi33.carprojectserver.interceptors.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand All @@ -18,4 +19,11 @@ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor)
.excludePathPatterns("/api/insert");
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("https://gh.xuanzhi33.cn", "http://127.0.0.1:5500")
.maxAge(3600);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public SensorDataController(SensorDataService dataService) {
}

@PostMapping("/get")
@CrossOrigin(origins = "https://gh.xuanzhi33.cn")
public Result<PagedSensorDataVO> getData(@Valid @RequestBody PageInfoDTO pageInfoDTO) {
int page = pageInfoDTO.getPage();
int pageSize = pageInfoDTO.getPageSize();
Expand All @@ -30,7 +29,6 @@ public Result<PagedSensorDataVO> getData(@Valid @RequestBody PageInfoDTO pageInf
}

@PostMapping("/insert")
@CrossOrigin(origins = "https://gh.xuanzhi33.cn")
public Result<Integer> insertData(@Valid @RequestBody SensorDataDTO sensorDataDTO) {
// Convert SensorDataDTO to SensorData
// Copy properties from sensorDataDTO to sensorData
Expand Down

0 comments on commit 6fa9e3e

Please sign in to comment.