PhoneGap and Couchbase Lite

127 views
Skip to first unread message

Mike Kirkup

unread,
Sep 14, 2014, 11:07:43 AM9/14/14
to mobile-c...@googlegroups.com
I have spent the past week trying to convert the Todo-lite sample over to use within my own application.  The Todo sample works on my simulator but any attempts to call the database directly using my own code are failing.  I feel like I must be missing something obvious here.

Reading through the documentation and code, the critical method to implement is getURL.  The return value from getURL is that the location of the couchbase lite database is at "http://lite.couchbase./".  Using the documentation for the REST API for couchbase lite (http://developer.couchbase.com/mobile/develop/references/couchbase-lite/rest-api/database/index.html) I should be able to simply call GET on the database and it will return basic information to confirm I am connecting.

So, I created my own code to talk to the database directly on the device:

            logMessage("Checking database connection");
            var url = "http://lite.couchbase./todo";

            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open('GET', url, false);
            xmlHttp.send();
            logMessage(" XML status: " + xmlHttp.status);
            logMessage(" XML status: " + xmlHttp.statusText);

For some reason, the code above returns a 404 error with no status text every single time.  I have tried using the coax class to create the URLs instead (e.g. var db = coax([url, appDbName]);) but continue to get the same response.  I would love some help in understanding what I am missing here!

Jens Alfke

unread,
Sep 14, 2014, 4:10:15 PM9/14/14
to mobile-c...@googlegroups.com

> On Sep 14, 2014, at 8:07 AM, Mike Kirkup <mki...@uwaterloo.ca> wrote:
>
> var url = "http://lite.couchbase./todo";

> For some reason, the code above returns a 404 error with no status text every single time.

Assuming this is a new app, did you create the 'todo' database first? It won't exist until you do a PUT to its URL. The usual idiom is to do the PUT first thing on every launch, and ignore a 412 error (that just means the database already exists.)

—Jens

Mike Kirkup

unread,
Sep 15, 2014, 5:25:05 AM9/15/14
to mobile-c...@googlegroups.com
Thanks Jens.  Really appreciate the help.

It is a new app and I can confirm that db.put is being called using the code from the sample.  

    function setupDb(db, cb) {
        logMessage("setupDb");
        db.get(function(err, res, body){
            logMessage(JSON.stringify(["db put - err:", err]))
            logMessage(JSON.stringify(["db put - res:", res]))
            logMessage(JSON.stringify(["db put - body:", body]))
            db.put(function(err, res, body){
                logMessage("setupDb - db.put");
                db.get(cb)
            })
        })

I also looked at the iOS simulator image through my filesystem and a cblite for todo is also being created which makes me think that the call is successful.  Any other suggestions?

Mike

Jens Alfke

unread,
Sep 15, 2014, 12:58:31 PM9/15/14
to mobile-c...@googlegroups.com
Weird. I don't know the JavaScript APIs, so hopefully someone else can help you further. (JChris is our point man for PhoneGap, but he's out on paternity leave right now.)

—Jens

Dominique Legault

unread,
Sep 16, 2014, 11:54:02 AM9/16/14
to mobile-c...@googlegroups.com
Have you setup a sync gateway and couchdb to sync to ?

What's your sync URL?

Mike Kirkup

unread,
Sep 16, 2014, 2:09:00 PM9/16/14
to mobile-c...@googlegroups.com
Yes, we have that all set up and are pulling data directly into our phone gap app from the Sync Gateway already.  We actually got this point of the problem because we needed to start uploading data and realized that this could only be done through one of the SDKs.  The sync URL is http://scoremorebaseball.com.

Mike

Dominique

unread,
Sep 17, 2014, 10:06:18 AM9/17/14
to mobile-c...@googlegroups.com

Are you running your sync gateway on port 80? Or 4984?

So what I hear you saying is your able to update data on the couchdb server and replicate the data on the client through the sync gateway but the problem your having is pushing the data from the client to the server?

What's the error you get in The device logs when you run the app?

Are you able to get the todo phonegap app running with your sync gateway?

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/5hX1lCVUvjs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/d0a90391-091b-4653-9fd1-8aa7f3173d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Sep 17, 2014, 11:53:46 AM9/17/14
to mobile-c...@googlegroups.com

On Sep 17, 2014, at 7:06 AM, Dominique <deefac...@gmail.com> wrote:

Are you running your sync gateway on port 80? Or 4984? 

Um, Dominique, why do you keep asking about the gateway and replication? My understanding is that Mike can't even access his local database, much less get replication started. He said: "any attempts to call the database directly using my own code are failing".

(Or if that's not your problem, Mike, and you can actually replicate, then could you please re-state your problem more explicitly?)

—Jens

Mike Kirkup

unread,
Sep 17, 2014, 12:20:57 PM9/17/14
to mobile-c...@googlegroups.com
Thanks Jens and Dominique.  

Jens is correct that we cannot even connect using the REST API to the local database such that we haven't hit any of the problems with our backend.  I can see the database being created on the simulator (especially when wiping it each time) but simply cannot understand why the PhoneGap plugin is not able to convert the request from the JSON API to the local Objective C calls.  I feel like I must be missing something simple but for some reason no one else knows the answer...

Mike

Jens Alfke

unread,
Sep 17, 2014, 12:40:30 PM9/17/14
to mobile-c...@googlegroups.com
Mike, could you post your code somewhere (either in a reply, or to a gist if it's bigger) so we can take a look? Or email it to me, if it's sensitive? I'm not a JS expert but I might find a clue.

—Jens
Reply all
Reply to author
Forward
0 new messages