Search code examples
couchbasecouchbase-litecouchbase-sync-gateway

Couchbase Mobile (Sync Gateway) sample TODOlite application doesn't replicate; complains _facebook doesn't exist


My objective: get https://github.com/couchbaselabs/ToDoLite-iOS syncing with a Couchbase Server and sync gateway on localhost rather than the default demo URL.

I run sync gateway like so: bin/sync_gateway -url http://localhost:8091

And then the only thing I changed in the example is:

-#define kSyncGatewayUrl @"http://demo.mobile.couchbase.com/todolite"
+#define kSyncGatewayUrl @"http://localhost:4984/sync_gateway/"

And when I run

Error: Error Domain=CBLHTTP Code=404 "404 not_found" UserInfo=0x7ff11941fb50 {NSURL=http://localhost:4984/sync_gateway/_facebook, NSLocalizedFailureReason=not_found, NSLocalizedDescription=404 not_found}

How do I fix this?


Solution

  • I solved it. The reason is that I ran sync_gateway without enabling Facebook registration support.

    Normally this is done in config.json file. In fact, this configuration file was supplied in ToDoLite all along.

    It is crucial that you launch sync_gateway with this configuration file. The README actually states this but in a loose and casual way...

    cd ToDoLite-iOS
    sync_gateway -url http://localhost:8091 sync-gateway-config.json
    

    NB: I assume above that sync_gateway has been made accessible through $PATH. It's a good idea to do that anyway.

    Also, I didn't pay attention to the dbname. So you'll need to replace

    #define kSyncGatewayUrl @"http://demo.mobile.couchbase.com/todolite"`
    

    with

    #define kSyncGatewayUrl @"http://localhost:4984/todos"
    

    So, what's the complete sequence of steps to get it working?:

    1. If you want to wipe everything on the server, rm -rf Library/Application\ Support/Couchbase and start over. Homebrew cask hides this setting somewhere else where it's hard to reset so a manual install is very recommended.

    2. Install Couchbase Server

    3. Set up login credentials if fresh install; otherwise just login

    4. Create a bucket (a database) with name todos on the cluster. This is the dbname used by TODOLite.

    5. Launch sync gateway. Be sure to pass in the replication URL AND the JSON config file. bin/sync_gateway -url http://localhost:8091 sync-gateway-config.json; keep sync gateway running

    6. In the TODOLite AppDelegate.m, change kSyncGatewayUrl: #define kSyncGatewayUrl @"http://localhost:4984/todos". Notice the name of the database is necessary!

    7. (Optionally) Access the administrator interface of the sync gateway by going to http://localhost:4985/_admin/db/sync_gateway/sync. You can set up the sync function here.


    In case you're wondering where those port numbers came from, check out