Does CouchbaseLiteSwift framework sync gateway works on localhost servers only?

I am accessing localhost server using syncgateway. But now I want to use another rest api instead of localhost server .Can I use other server api for CouchbaseLiteSwift? Will replication doe correctly?
I am using CouchbaseLiteSwift 2.6.0

Yes of course, otherwise it would not be very useful. Has something given you the impression that you cannot?

Ok thanks! I am trying to use IBM cloud server database and when I try to access it ,getting following errors continuously.That’s why I was confused.

019-10-02 10:51:13.844667+0530 To-Do-List[863:13782] CouchbaseLite Network WARNING: {C4SocketImpl#5} Unexpected or unclean socket disconnect! (reason=WebSocket status, code=404)

2019-10-02 10:51:13.847586+0530 To-Do-List[863:13782] CouchbaseLite Replicator ERROR: {Repl#3} Got LiteCore error: WebSocket error 404 "Object Not Found"

It looks like for whatever reason either you don’t have the bucket created on that server (likely) or you are using 1.x on that server by mistake (less likely).

Database is present on server with no documents!
I have some basic queries. Please help me into this.

1)I am following format for sync url?is it right?

wss://your_host:443/todoslist

2)On Mac , what is the location for sync_gateway_config.json? Does it require to update if I want to use IBM Cloud server or any other server?

3)When I try to use online server , do I need to start sync gateway using terminal every time?

wss://your_host:443/todoslist

That’s correct if the Sync Gateway is listening on port 443 and the database/bucket name is todoslist. The port number is specified in the SG config file.

On Mac , what is the location for sync_gateway_config.json?

It can go anywhere. You pass the path of the config file as an argument to sync_gateway.

Does it require to update if I want to use IBM Cloud server or any other server?

The config file has to be on the server, because Sync Gateway is running on the server and it has to read the config file when it starts.

Hey thanks for your reply!! I need more clarification . Do I need to create sync gateway config file or it is already present after installing the sync gateway?. I did’n find the file.But need to clear these things from my side.

For now , I have created sync_gateway_config file to check
{
“log”: [""],
“databases”: {
“db”: {
“server”: “http://ibm_cloud_host:443”,
“bucket”: “default”,
“users”: {
“GUEST”: {“disabled”: false, “admin_channels”: ["
"] }
}
}
}
}
Executed following command
~/Downloads/couchbase-sync-gateway/bin/sync_gateway sync_gateway_config.json
It is giving me error like:
json

2019-10-04T11:45:26.267+05:30 [ERR] Error reading config file sync_gateway_config.json: open sync_gateway_config.json: no such file or directory – rest.ServerMain() at config.go:1283

Can you explain exact requirements for sync gateway process?

I think you are trying to make it more complicated than it is. The JSON file is passed to sync gateway as an argument on startup. You can do this directly from the command line or you can set up some kind of service / daemon that does it but at the end of the day you start up Sync Gateway by passing in the config file as an argument. The error you show indicates that you passed in a path to a non-existent file.

This is all explained in the Getting Started section of the documentation.

Yes …done with it!! Now I have updated config file
{
“logging.console.log_keys”: [""],
“databases”: {
“to_do_list”: {
“server”: “ibm.cloud:443”,
“bucket”: “to_do_list”,
“username”: “”,
“password”: “”,
“enable_shared_bucket_access”: true,
“import_docs”: true,
“num_index_replicas”: 0,
“users”: {
“GUEST”: { “disabled”: false, “admin_channels”: ["
"] }
},
“sync”: function (doc, oldDoc) { if (doc.sdk) { channel(doc.sdk); } }
}
}
}
And run the sync gateway config file on server .It is not giving any issues now.But when I try to run iOS app , I am facing same issue
2019-10-04 13:38:35.501371+0530 To-Do-List[854:16329] CouchbaseLite Network WARNING: {C4SocketImpl#4} Unexpected or unclean socket disconnect! (reason=WebSocket status, code=404)

2019-10-04 13:38:35.507442+0530 To-Do-List[854:16329] CouchbaseLite Replicator ERROR: {Repl#3} Got LiteCore error: WebSocket error 404 "Object Not Found"

But when I use “log” instead of “logging.console.log_keys” in config file ,I am receiving following issue:

Attempting credential authentication…
Error opening database to_do_list: 502 Unable to connect to Couchbase Server (connection refused). Please ensure it is running and reachable at the configured host and port.

Please ensure Couchbase Server is running and reachable [to Sync Gateway] at the configured host and port.

“server”: “ibm.cloud:443”

That can’t be correct. I ran curl https://ibm.cloud:443 and it just times out.
In a browser, https://ibm.cloud redirects to their home page.
The IBM Cloud home page doesn’t say anything about Couchbase Server that I can see; you do realize that you need Couchbase Server?

Hey the ibm server is reachable at the configured host .The format of the url is as follows:
https://ibm_cloud…:443/to_do_list
The server is not reachable when I use wss instead of https.

But when I try to connect with the server using sync gateway in Xcode , I receive the issue 404 object not found.(On server side I have given permission read & write access to database)

When I disabled read & write access to the database on server side, then I received error as Unauthorized in Xcode logs.

Is there connections established between client & server? Need your inputs on both the points

As Jens indicated, you need a Couchbase server for Sync Gateway to talk to. Is the server property specified in the Sync gateway config file pointing to a valid Couchbase server . You cannot point Sync Gateway to a non-Couchbase server database. So not sure what the IBM cloud server database is …

Why would you think that you could use Sync Gateway with some totally unrelated database from IBM? Does it say anything in our docs about supporting “IBM Cloud”?

Ok…Actually I am new to this .


The IBM Cloudant supports document type database.So I thought to make a try with it.
If sync gateway only supports to Couchbase Server then I need to try with it.

Installation of Couchbase server is discussed in our Sync Gateway startup guide

:exploding_head: There are probably a thousand types of databases in the world, all different. It’s like saying a file is a “document” — it tells you nothing about what kind of software can read it.

Thank you @jens and @priya.rajagopal for your reply. I have installed Couchbase Server on machine .

{
“log”: [""],
“databases”: {
“to_do_list”: {
“server”: “http://localhost:8091”,
“bucket”: “to_do_list”,
“username”: “sync_gateway”,
“password”: “password”,
“enable_shared_bucket_access”: true,
“import_docs”: true,
“num_index_replicas”: 0,
“users”: {
“GUEST”: { “disabled”: false, “admin_channels”: ["
"] }
},
“sync”: function (doc, oldDoc) { if (doc.sdk) { channel(doc.sdk); } }
}
}
}
This is my sync_gateway_config.json file.After executing this on my terminal.I receive following output.
$ ~/Downloads/couchbase-sync-gateway/bin/sync_gateway ~/Documents/sync_gateway_config.json
2019-10-15T10:29:18.202+05:30 ==== Couchbase Sync Gateway/2.6.0(127;b4c828d) EE ====
2019-10-15T10:29:18.203+05:30 [WRN] Using deprecated config option: “log”. Use “logging.console.log_keys” instead. – rest.(*ServerConfig).deprecatedConfigLoggingFallback.func5() at config.go:900
2019-10-15T10:29:18.204+05:30 [INF] Logging: Console to stderr
2019-10-15T10:29:18.204+05:30 [INF] Logging: Files disabled
2019-10-15T10:29:18.204+05:30 [ERR] No log_file_path property specified in config, and --defaultLogFilePath command line flag was not set. Log files required for product support are not being generated. – base.(*LoggingConfig).Init.func1() at logging_config.go:61
2019-10-15T10:29:18.204+05:30 [WRN] Using deprecated config value for “import_docs”: “continuous”. Use “import_docs”: true instead. – rest.(DbConfig).AutoImportEnabled() at config.go:426
2019-10-15T10:29:18.204+05:30 [INF] Logging: Console level: info
2019-10-15T10:29:18.204+05:30 [INF] Logging: Console keys: [
HTTP]
2019-10-15T10:29:18.204+05:30 [INF] Logging: Redaction level: none
2019-10-15T10:29:18.205+05:30 [INF] Configured process to allow 5000 open file descriptors
2019-10-15T10:29:18.205+05:30 [INF] Logging stats with frequency: 1m0s
2019-10-15T10:29:18.205+05:30 [INF] Opening db /to_do_list as bucket “to_do_list”, pool “default”, server http://127.0.0.1:8091
2019-10-15T10:29:18.205+05:30 [WRN] Using deprecated config value for “import_docs”: “continuous”. Use “import_docs”: true instead. – rest.(*DbConfig).AutoImportEnabled() at config.go:426
2019-10-15T10:29:18.205+05:30 [INF] GoCBCustomSGTranscoder Opening Couchbase database to_do_list on http://127.0.0.1:8091 as user “sync_gateway”
2019-10-15T10:29:18.211+05:30 [INF] Auth: Attempting credential authentication http://127.0.0.1:8091?http_idle_conn_timeout=90000&http_max_idle_conns=64000&http_max_idle_conns_per_host=256&n1ql_timeout=75000
2019-10-15T10:29:18.221+05:30 [INF] Successfully opened bucket to_do_list
2019-10-15T10:29:18.229+05:30 [INF] Set query timeouts for bucket to_do_list to cluster:1m15s, bucket:1m15s
2019-10-15T10:29:18.229+05:30 [INF] Initializing indexes with numReplicas: 0…
2019-10-15T10:29:18.248+05:30 [INF] Query: Index sg_syncDocs_x1 doesn’t exist, creating…
2019-10-15T10:29:18.272+05:30 [WRN] Error creating index sg_syncDocs_x1: Error creating index with statement: CREATE INDEX sg_syncDocs_x1 ON to_do_list(META().id) WHERE META().id LIKE ‘\_sync:%’ with {“defer_build”:true}. Error: [13014] User does not have credentials to run index operations. Add role query_manage_index on to_do_list to allow the query to run. - will retry. – db.(*SGIndex).createIfNeeded.func1() at indexes.go:255
2019-10-15T10:29:18.281+05:30 [WRN] Error creating index sg_syncDocs_x1: Error creating index with statement: CREATE INDEX sg_syncDocs_x1 ON to_do_list(META().id) WHERE META().id LIKE ‘\_sync:%’ with {“defer_build”:true}. Error: [13014] User does not have credentials to run index operations. Add role query_manage_index on to_do_list to allow the query to run. - will retry. – db.(*SGIndex).createIfNeeded.func1() at indexes.go:255
2019-10-15T10:29:18.296+05:30 [WRN] Error creating index sg_syncDocs_x1: Error creating index with statement: CREATE INDEX sg_syncDocs_x1 ON to_do_list(META().id) WHERE META().id LIKE ‘\_sync:%’ with {“defer_build”:true}. Error: [13014] User does not have credentials to run index operations. Add role query_manage_index on to_do_list to allow the query to run. - will retry. – db.(*SGIndex).createIfNeeded.func1() at indexes.go:255
2019-10-15T10:56:28.042+05:30 [ERR] Error opening database to_do_list: Unable to install index access: Error creating index with statement: CREATE INDEX sg_access_x1 ON to_do_list(ALL (ARRAY (op.name) FOR op IN OBJECT_PAIRS(meta().xattrs._sync.access) END)) with {“retain_deleted_xattr”:true,“defer_build”:true}. Error: [13014] User does not have credentials to run index operations. Add role query_manage_index on to_do_list to allow the query to run. – rest.RunServer() at config.go:1208

Any changes required in this file?

What permissions does the user “sync_gateway” RBAC user have on the bucket? You should have configured this on the server when you set up the user

I have given role to the user as “Read-only-admin” .I don’t know how to check pemissions for user “sync_gateway” on the bucket? Please tell me.

And I want to know how can I use this as online server ? Means when no localhost available & sync gateway is not started , how can I operate the app on mobile device ?There will bel no syncing with server & client?