Raod 3 years ago
parent a886f8d028
commit b2dbff671d

@ -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 {
}
}

@ -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() {
}
}

@ -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();
}
}

@ -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();
}
}

@ -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"'
})

Loading…
Cancel
Save