Skip to content

Commit

Permalink
added cors filter, bumped version for release, updated readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
armzilla committed May 19, 2015
1 parent fad68be commit 5aa6ae5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.armzilla.ha</groupId>
<artifactId>amazon-echo-bridge</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<packaging>jar</packaging>

<name>Amazon Echo Bridge</name>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/armzilla/ha/filters/SpringBootCorsFilter.java
Original file line number Diff line number Diff line change
@@ -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() {}

}

0 comments on commit 5aa6ae5

Please sign in to comment.