Stefan,

Over 1 year later, this code still works. Huge help, Dude. Thanks for the 
post.

- Michael

On Tuesday, June 10, 2014 at 12:10:22 AM UTC+8, [email protected] wrote:
>
> So I tried out my approach and it works. You have to do two things:
>
> 1) add the specific CORS headers to each response
> 2) handle OPTIONS requests, since these requests are automatically send 
> from most of the browsers as a "preflight" CORS request and couchbase light 
> has no handler for the OPTIONS method.
>
> The class to be modified:
>
> https://github.com/couchbase/couchbase-lite-java-listener/blob/master/src/main/java/com/couchbase/lite/listener/LiteServlet.java
>
> The code:
>
> @Override
> public void service(HttpServletRequest request, final HttpServletResponse 
> response)throws ServletException, IOException {
>
> // Handle OPTIONS request in order to respond to CORS
> response.setHeader("Access-Control-Allow-Origin", "*");
> response.setHeader("Access-Control-Allow-Methods", "GET, PUT, POST, 
> DELETE");
> response.setHeader("Access-Control-Allow-Headers", "content-type, accept");
> if("OPTIONS".equals(request.getMethod())){
>   Log.v(Log.TAG_LISTENER, "Handle OPTIONS request in order to respond to 
> CORS");
>   response.setStatus(200);
>   return;
> }
> ...
> }
>
> I also attached the modified library for the Phonegap plugin for Android 
> (couchbase-lite-java-listener-1.0.0-72.jar).
>
> Hope that helps, cheers,
> Stefan
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/3edae456-ef6d-4cb7-a1fb-610258e21a04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to