package com.google.sticknotesbackend;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class RedirectFilter implements Filter {
  private FilterConfig config = null;

  public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    ServletContext context = config.getServletContext();
    HttpServletRequest httpRequest = (HttpServletRequest)request;
    String requestedUrl = httpRequest.getRequestURL().toString();
    // if request is not to API, redirect it to 'index.html', otherwise do nothing
    if (!requestedUrl.startsWith("api/")) {
      // request to angular, forward it to the index.html
      RequestDispatcher dispatcher = context.getRequestDispatcher("/index.html");
      dispatcher.forward(request, response);
    }
  }

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    this.config = filterConfig;
  }

  @Override
  public void destroy() {
    // TODO Auto-generated method stub
  }
}

@@ -759,74 +759,8 @@
 st;%0A
-    String requestedUrl = httpRequest.getRequestURL().toString();%0A
     
@@ -792,16 +792,15 @@
 PI, 
-redirect
+forward
  it 
@@ -850,38 +850,55 @@
 f (!
-requestedUrl.startsWith(%22api/%22
+isApiUrl(httpRequest.getRequestURL().toString()
 )) %7B
@@ -1090,24 +1090,130 @@
 %0A    %7D%0A  %7D%0A%0A
+  private boolean isApiUrl(String url) %7B%0A    return url.startsWith(%22api%22) %7C%7C url.startsWith(%22/api%22);%0A  %7D%0A%0A
   @Override%0A
@@ -1325,32 +1325,32 @@
  %7D%0A%0A  @Override%0A
+
   public void de
@@ -1362,50 +1362,8 @@
 () %7B
-%0A    // TODO Auto-generated method stub%0A  
 %7D%0A%7D%0A

Implement isApiUrl method