Commit ca00070b authored by zengtianlai3's avatar zengtianlai3

接口调整,跨域问题真正解决

parent 1115ec57
......@@ -12,16 +12,12 @@ public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOriginPatterns("*")
// 是否允许证书 不再默认开启
.allowCredentials(true)
// 设置允许的方法
.allowedMethods("*")
// 跨域允许时间
.maxAge(3600);
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
}
@Override
......
package iot.sixiang.license.controller;
import iot.sixiang.license.entity.Monitor;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-10
*/
@RestController
@RequestMapping("/iot_license/monitor")
public class MonitorController {
@Autowired
private MonitorService monitorService;
@PostMapping("add")
public boolean addMonitor(){
return monitorService.addMonitor(20);
}
@GetMapping("list")
public ResResult getMonitorList(@RequestParam("type") int type) {
HashMap<String,List<Integer>> monitorList = monitorService.getMonitorList(type);
return ResResult.success().record(monitorList);
}
}
package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.MonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Slf4j
......@@ -22,49 +18,27 @@ public class OperateController {
@Autowired
private OperateManager operateManager;
@Autowired
private AlarmService alarmService;
private MonitorService monitorService;
@GetMapping("monitor/server")
public ResResult getDeviceTypes() {
// List<JSONObject> list = new ArrayList<>();
// JSONObject obj = new JSONObject();
// obj.put("serverIp", "192.168.1.11");
// obj.put("samCount", 100);
// obj.put("onlineCount",55);
// list.add(obj);
// JSONObject obj2 = new JSONObject();
// obj2.put("serverIp", "192.168.1.12");
// obj2.put("samCount", 100);
// obj2.put("onlineCount",55);
// list.add(obj2);
List<SamMonitor> records = operateManager.getSamMonitorList();
return ResResult.success().record(records);
}
@PostMapping("monitor/add")
public boolean addMonitor() {
return monitorService.addMonitor(20);
}
@GetMapping("monitor/qps")
public ResResult getQps(@RequestParam("type") int type) {
List<JSONObject> list = new ArrayList<>();
JSONObject obj = new JSONObject();
obj.put("x", 1);
obj.put("y", 2);
list.add(obj);
JSONObject obj2 = new JSONObject();
obj2.put("x", 2);
obj2.put("y", 2);
list.add(obj2);
JSONObject obj3 = new JSONObject();
obj2.put("x", 3);
obj2.put("y", 3);
list.add(obj3);
return ResResult.success().record(list);
HashMap<String, List<Integer>> monitorList = monitorService.getMonitorList(type);
return ResResult.success().record(monitorList);
}
}
......@@ -5,6 +5,7 @@ import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
......@@ -30,12 +31,10 @@ public class JwtFilter implements Filter {
final HttpServletRequest request = (HttpServletRequest) servletRequest;
final HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setContentType("text/html; charset=utf-8");
response.setHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH");
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
filterChain.doFilter(request, response);
return;
}
String token = request.getHeader("authorization");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment