Closed AdamDz closed 7 years ago
CBL has support for adding custom HTTP headers to return; see https://github.com/couchbase/couchbase-lite-ios/pull/203 . The PhoneGap plugin just needs to add this line:
[[CBLManager sharedInstance].customHTTPHeaders setObject:@"*" forKey:@"Access-Control-Allow-Origin"];
The ideal solution would be to add support for setting custom HTTP headers using the REST API. The PhoneGap plugin would then have the same feature set.
I need to admit that your solution works well and doesn't require to recompile CBL binaries. The mentioned line can be added in src/ios/CBLine.m and it works. Thanks.
I had the same issue on Android. For debugging purpose, I wanted to access my cblite on the mobile device from my local web application (using "ionic serve"). You need to do two things: 1) Tunnel the cblite port from your local machine to your phone: "adb forward tcp:5984 tcp:5984" 2) Recompile the couchbase-light-java-listener JAR. Add the following lines to the LiteServlet.java file:
@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;
}
/* REST OF THE service() METHOD */
}
Thats it.
See also https://groups.google.com/forum/#!msg/mobile-couchbase/a80GfiBwkuI/MoBtQNT8zPUJ where I started the discussion month's ago.
we now have a version of LiteServ with CORS available for development purposes https://developer.couchbase.com/documentation/mobile/1.4/installation/phonegap/index.html#development-environment. Closing this ticket.
I'm still having this issue, is there a way to fix this?
Couchbase Lite does not work with rapid development tools that implement live app reload and eliminate the compile and install step (i.e. calling
cordova run
every JS/HTML change). These tools include: GapReload and Adobe's PhoneGap Developer App. They work by redirecting the webview from afile://
location to a server on the developer's machine started bycordova serve
. When we try to connect to Couchbase Lite in such setup, an error is thrown:The cross-resource origin policy is not applied when the embedded web application is served from the standard location using
file://
, but it is after the redirection tohttp://
A solution would be to add a header to HTTP responses returned by Couchbase Lite: