diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java new file mode 100644 index 0000000..4535da1 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java @@ -0,0 +1,32 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import java.io.IOException; +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import org.springframework.stereotype.Component; + +/** + * Add CORS headers to each response in order to please the frontend requests, coming from a + * different host for now (thanks to the difference in ports). Andrea would you please stop + * complaining now + */ +@Component +public class CORSFilter implements Filter { + + @Override + 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", "HEAD, PUT, POST, GET, OPTIONS, DELETE"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); + chain.doFilter(req, res); + } + + @Override + public void init(FilterConfig filterConfig) {} + + @Override + public void destroy() {} +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java index a8c86a5..041f7c7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java @@ -68,8 +68,9 @@ public class SpringFoxConfig { */ private Predicate paths() { return regexPredicate("/auth.*") - .or(regexPredicate("/room.*")) - .or(regexPredicate("/register.*")); + .or(regexPredicate("/room.*")) + .or(regexPredicate("/register.*")) + .or(regexPredicate("/")); } /** diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java index cc9ed2e..0cf7bbe 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java @@ -17,7 +17,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.*; @RestController -@CrossOrigin @RequestMapping("/auth") public class AuthenticationController { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index 8cbb5d5..a81eec6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -1,23 +1,15 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; -import java.util.*; import org.springframework.boot.autoconfigure.*; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration -// @Mapping("/light") public class WelcomeController { @GetMapping - List testDevices() { - return Arrays.asList( - new KnobDimmer(), - new RegularLight(), - new MotionSensor(), - new Sensor(), - new SmartPlug(), - new Switch()); + ResponseEntity testConnection() { + return ResponseEntity.ok(null); } }