Skip to content

Commit

Permalink
3.0.1: add CORS filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kolya-t committed Sep 27, 2017
1 parent 2d087db commit b9e971b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.teapot</groupId>
<artifactId>teapot-backend</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<packaging>jar</packaging>

<parent>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/teapot/backend/config/CorsFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.teapot.backend.config;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class CorsFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods",
"POST, GET, PATCH, DELETE, OPTIONS");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers",
"x-requested-with, Content-Type, Authorization, Accept");

filterChain.doFilter(request, response);
}
}

0 comments on commit b9e971b

Please sign in to comment.