From 5aa6ae504b61662814624e66fb5a34a9ab6395cb Mon Sep 17 00:00:00 2001 From: arm Date: Mon, 18 May 2015 23:56:59 -0500 Subject: [PATCH] added cors filter, bumped version for release, updated readme.md --- README.md | 3 +- pom.xml | 2 +- .../ha/filters/SpringBootCorsFilter.java | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/armzilla/ha/filters/SpringBootCorsFilter.java diff --git a/README.md b/README.md index 86c9221..e8c6632 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,5 @@ somewhat hacked together for now, please excuse the hard coded values grab the jar, run like this: ``` -java -jar amazon-echo-bridge-0.1.0.jar --upnp.config.address=192.168.1.240 +java -jar amazon-echo-bridge-0.1.0.jar ``` -replace the --upnp.config.address value with the server ipv4 address. To force ipv4 in java you can add the system property -Djava.net.preferIPv4Stack=true diff --git a/pom.xml b/pom.xml index c346b2a..ba1f985 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.armzilla.ha amazon-echo-bridge - 0.1.1 + 0.1.2 jar Amazon Echo Bridge diff --git a/src/main/java/com/armzilla/ha/filters/SpringBootCorsFilter.java b/src/main/java/com/armzilla/ha/filters/SpringBootCorsFilter.java new file mode 100644 index 0000000..0d0fa40 --- /dev/null +++ b/src/main/java/com/armzilla/ha/filters/SpringBootCorsFilter.java @@ -0,0 +1,35 @@ +package com.armzilla.ha.filters; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import org.springframework.stereotype.Component; + +/** + * https://spring.io/guides/gs/rest-service-cors/ + * for some reason i thought chrome would send only preflight HEAD request BEFORE the actual call? + * + * also.. component scan is making me really lazy + */ +@Component +public class SpringBootCorsFilter implements Filter { + + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + HttpServletResponse response = (HttpServletResponse) res; + response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); + chain.doFilter(req, res); + } + + public void init(FilterConfig filterConfig) {} + + public void destroy() {} + +} \ No newline at end of file