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.
{
"databases": {
"mydb": {
"cors": {
"origin": ["https://mywebsite.com"],
"login_origin": ["https://mywebsite.com"],
"headers": ["Authorization"]
}
}
}
}
Required CORS Properties:
-
origin- Specify the exactorigin(Access-Control-Allow-Origin) of your front-end application. Avoid using the wildcard*, as authentication requires explicit origins. -
login_origin- Specify the exactlogin_originof your front-end application. Avoid using the wildcard*, as authentication requires explicit origins. -
headers- Must include"Authorization"header