CORS Configuration

      +

      Description — Couchbase Lite JavaScript — CORS Configuration for Replication with Sync Gateway
      Related Content — Remote Sync Gateway | Handling Data Conflicts

      Overview

      Cross-Origin Resource Sharing (CORS) configuration is essential for enabling Couchbase Lite JavaScript to communicate and sync data with Sync Gateway from browser applications. Due to browser security restrictions, web applications must be explicitly allowed to make cross-origin requests to Sync Gateway.

      This page explains the CORS requirements for Couchbase Lite JavaScript, how to configure Sync Gateway properly.

      CORS Configuration

      Configuring CORS settings for Sync Gateway is a prerequisite for enabling data syncronization with the JavaScript SDK. The CORS configuration should be done in the Sync Gateway Bootstrap Configuration.

      Minimum CORS Settings

      Sync Gateway must be configured with CORS settings that allow your web application’s origin.

      Example 1. Sync Gateway CORS Configuration
      {
        "databases": {
          "mydb": {
            "cors": {
              "origin": ["https://mywebsite.com"],
              "login_origin": ["https://mywebsite.com"],
              "headers": ["Authorization"]
            }
          }
        }
      }

      Required CORS Properties:

      • origin - Specify the exact origin (Access-Control-Allow-Origin) of your front-end application. Avoid using the wildcard *, as authentication requires explicit origins.

      • login_origin - Specify the exact login_origin of your front-end application. Avoid using the wildcard *, as authentication requires explicit origins.

      • headers - Must include "Authorization" header

      How to . . .

      .

      Dive Deeper . . .

      Mobile Forum | Blog | Tutorials

      .