diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CORSFilter.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CORSFilter.java new file mode 100644 index 00000000..42d50061 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CORSFilter.java @@ -0,0 +1,42 @@ +package com.anjiplus.template.gaea.business.filter; + +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created by raodeming on 2021/6/24. + */ +@Component +public class CORSFilter implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + // 设置允许Cookie + res.addHeader("Access-Control-Allow-Credentials", "true"); + // 允许http://www.xxx.com域(自行设置,这里只做示例)发起跨域请求 + res.addHeader("Access-Control-Allow-Origin", "*"); + // 设置允许跨域请求的方法 + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + // 允许跨域请求包含content-type + res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN"); + if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) { + response.getWriter().println("ok"); + return; + } + chain.doFilter(request, response); + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CorsFilter.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CorsFilter.java deleted file mode 100644 index 904cbe8e..00000000 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/CorsFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - *Copyright © 2018 anji-plus - *安吉加加信息技术有限公司 - *http://www.anji-plus.com - *All rights reserved. - */ -package com.anjiplus.template.gaea.business.filter; -/** - * 本地启动解决跨域问题 - * Created by raodeming on 2021/06/24. - */ -import org.springframework.context.annotation.Configuration; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@WebFilter(filterName = "CorsFilter ") -@Configuration -public class CorsFilter implements Filter { - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) - throws ServletException, IOException { - HttpServletResponse response = (HttpServletResponse) servletResponse; - HttpServletRequest request = (HttpServletRequest) servletRequest; - response.setContentType("application/json; charset=utf-8"); - response.setCharacterEncoding("UTF-8"); - response.setHeader("Access-Control-Max-Age", "3600"); - response.setHeader("Access-Control-Allow-Methods", "POST, GET,PUT, OPTIONS, DELETE");//http请求方式 - response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); - response.setHeader("Access-Control-Allow-Credentials", "true"); - response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token"); - filterChain.doFilter(request, response); - } - - @Override - public void destroy() { - - } -} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java index 1fe886b9..707c4bf1 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java @@ -70,6 +70,5 @@ public class TokenFilter implements Filter { private void error(HttpServletResponse response) throws IOException { ResponseBean responseBean = ResponseBean.builder().code("500").message("The Token has expired").build(); response.getWriter().print(JSONObject.toJSONString(responseBean)); - response.getOutputStream().flush(); } } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/user/controller/LoginController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/user/controller/LoginController.java index 405b9f0b..5a66899a 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/user/controller/LoginController.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/user/controller/LoginController.java @@ -31,4 +31,9 @@ public class LoginController { public ResponseBean login(@RequestBody @Validated GaeaUserDTO dto) { return ResponseBean.builder().data(userService.login(dto)).build(); } + + @PostMapping({"/health"}) + public ResponseBean health() { + return ResponseBean.builder().build(); + } } diff --git a/report-ui/config/dev.env.js b/report-ui/config/dev.env.js index 5c6289bb..f50fc84e 100644 --- a/report-ui/config/dev.env.js +++ b/report-ui/config/dev.env.js @@ -4,6 +4,6 @@ const prodEnv = require('./prod.env') module.exports = merge(prodEnv, { NODE_ENV: '"development"', - // BASE_API: '"http://10.108.26.163:8080"' - BASE_API: '"http://10.108.26.197"' + // BASE_API: '"http://127.0.0.1:9095"' + BASE_API: '"http://10.108.26.197:9095"' })