Skip to content

Commit 7eb4ad0

Browse files
committed
DA-635 Added Couchbase Edge Server Tutorial
1 parent d20b42a commit 7eb4ad0

10 files changed

+187
-0
lines changed
85 KB
Loading
172 KB
Loading
142 KB
Loading
68.3 KB
Loading
373 KB
Loading
157 KB
Loading
86.7 KB
Loading
24.4 KB
Loading
94.1 KB
Loading
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
---
2+
# frontmatter
3+
path: "/tutorial-couchbase-edge-server-demo"
4+
title: "Explore Couchbase Edge Server with seat back application"
5+
short_title: "Couchbase Edge Server Demo"
6+
description:
7+
- Learn how to set up Couchbase Edge Server
8+
- Explore seatback meal-application showcasing Couchbase Edge Server capabilities
9+
- Explore data synchronization between edge and cloud deployments
10+
content_type: tutorial
11+
filter: mobile
12+
technology:
13+
- app-services
14+
- edge-server
15+
- react
16+
- mobile
17+
tags:
18+
- Couchbase Edge Server
19+
- Capella App Services
20+
- Mobile
21+
length: 45 Mins
22+
---
23+
24+
## Introduction
25+
26+
The sample React-based web application simulates an airline seat back application, that allows users in business and economy class to place their in-flight meal orders. The sample app leverages **Couchbase Edge Server** for data storage and processing at the edge, simulating a disconnected offline experience within an aircraft. The seatback web app accesses Edge Server via a RESTful interface. When there is Internet connectivity, the **Edge Server** syncs data with remote Capella App Services.
27+
28+
## Setup & Technology Stack
29+
30+
The setup would be as follows:
31+
32+
![](./edge-sample-app-setup.png)
33+
34+
* Capella / Capella App Services
35+
* Couchbase Edge Server
36+
* Sample web application
37+
38+
## Installation Instructions
39+
### Capella Cluster Setup
40+
Although instructions are specified for Capella, equivalent instructions apply to self-managed Couchbase Server as well.
41+
42+
* Sign up for Capella Free Tier and [follow the steps](https://docs.couchbase.com/cloud/get-started/create-account.html) to deploy a free tier cluster.
43+
* Follow [instructions to create a bucket](https://docs.couchbase.com/cloud/clusters/data-service/manage-buckets.html#add-bucket) to create a *bucket* named "mealordering".
44+
* Follow [scope creation instructions](https://docs.couchbase.com/cloud/clusters/data-service/about-buckets-scopes-collections.html#scopes) to create a *scope* named "AmericanAirlines" and follow the [instructions to create a collection](https://docs.couchbase.com/cloud/clusters/data-service/about-buckets-scopes-collections.html#collections) to create a *collection* named "AA234".
45+
46+
![](./edge-sample-create-doc.png)
47+
* Download **"mealordering.zip"** sample data set from [this location](https://edge-server-tutorial-data.s3.us-east-2.amazonaws.com/mealordering.zip). It includes 4 documents:
48+
- businessinventory.json
49+
- businessmeal.json
50+
- economyinventory.json
51+
- economymeal.json
52+
53+
* Follow [instructions](https://docs.couchbase.com/cloud/clusters/data-service/manage-documents.html#create-documents) to create sample documents corresponding to each of the documents above. Add them to specified bucket named "mealordering", scope named "AmericanAirlines", and collection named "AA234" created in the previous step. For example, create a document with docId of "businessinventory" and copy the contents of the sample JSON file to the document body.
54+
55+
![](./create-new-document.png)
56+
57+
At the end of the setup, your Capella Setup looks like this:
58+
![](./edge-sample-cluster.png)
59+
60+
### Capella App Services
61+
Although instructions are specified for Capella App Services, equivalent instructions apply to self-managed Sync Gateway as well.
62+
63+
* Follow [instructions](https://docs.couchbase.com/cloud/get-started/create-account.html#app-services) to create a free tier App Services that links to the free tier cluster created in previous step.
64+
* Create an *App Endpoint* named "american234" by following these [instructions](https://docs.couchbase.com/cloud/get-started/configuring-app-services.html#create-app-endpoint). When you create the App Endpoint, link it to the bucket named "mealordering", the scope named "AmericanAirlines", and the collection named "AA234".
65+
66+
The configuration should look something like this:
67+
![](./edge-sample-appendpoint.png)
68+
69+
* Create an App User named "edgeserver234". Remember the password you use as you will need to configure your Edge Server later.
70+
- Set up the access grant so the App User is granted access to the channel named "AA234" in the corresponding collection.
71+
72+
The configuration of App User should look something like this:
73+
74+
![](./edge-sample-app-user.png)
75+
76+
* Go to the "connect" tab and record the public URL endpoint. You will need it when you configure your Edge Server.
77+
78+
![](./edge-sample-connect.png)
79+
80+
### Couchbase Edge Server Setup
81+
The instructions below describe how to deploy and run edge server on your local Mac machine. The equivalent instructions should apply to Linux-based machines as well.
82+
83+
* Download Edge Server binary from the [downloads page](https://www.couchbase.com/downloads?family=edge-server).
84+
* Download the associated configuration .zip file named **"config-edge-server.zip"** from this [location](https://edge-server-tutorial-data.s3.us-east-2.amazonaws.com/config-edge-server.zip).
85+
* Unzip the contents of the package and place them in the same directory as your Edge Server executable. It will include the following:
86+
- **usersfile**: This includes the list of web users who can access data from Edge Server. These are the credentials with which the web app authenticates with the server.
87+
- [Optional] If you are interested in learning about how to generate your own users, run `./couchbase-edge-server --help` command to get more details.
88+
- **certfile.pem** and **keyfile**: The edge server is configured to start up with an anonymous self-signed certificate with a "common name" of localhost. This is the cert file and private key corresponding to that.
89+
- [Optional] If you are interested in how you can generate your own anonymous self-signed certfile and keyfile, run the `./couchbase-edge-server --help` command to get more details. We'd recommend you follow the Edge Server documentation to generate your own certificate and private key.
90+
* Open the config file named "config-tls-replication-sync.json" and edit the file as follows:
91+
- In the Replication section, replace these placeholders:
92+
93+
```json
94+
{
95+
"replications": [
96+
{
97+
// setup a bidirectional continuous replication
98+
"source": "<<REPLACE WITH THE PUBLIC URL FROM CONNECT PAGE>>",
99+
"target": "american234",
100+
"bidirectional": true,
101+
"continuous": true,
102+
"collections": {
103+
"AmericanAirlines.AA234": {}
104+
},
105+
"auth": {
106+
"user": "edgeserver234", // user setup on remote app services/Sync Gateway
107+
"password": "<<REPLACE WITH PASSWORD OF APP USER>>" // user setup on remote app services/Sync Gateway
108+
}
109+
}
110+
]
111+
}
112+
```
113+
114+
- The source should correspond to the public URL that you get from the Connect tab of App Endpoint.
115+
- The password should be the password corresponding to the App User that you created on App Endpoint.
116+
117+
* Start the edge server. It will start listening for incoming connections on port 60000 (you can change that in your config file):
118+
119+
```bash
120+
./couchbase-edge-server --verbose config-tls-replication-sync.json
121+
```
122+
123+
If everything is set up properly, the Edge Server will sync down documents from remote App Services.
124+
125+
### Web App Setup
126+
127+
Follow these steps to set up and run the application locally on the same machine as the Edge Server:
128+
129+
* **Clone the Repository**:
130+
```bash
131+
git clone <repository-url>
132+
cd edge-server-sko-demo
133+
```
134+
135+
* **Install Dependencies**:
136+
Ensure you have **Node.js** (version 16 or later) installed. Then, install the required dependencies by running:
137+
```bash
138+
npm install
139+
```
140+
141+
* **Create .env File**:
142+
Create a .env file in the project root and define the URL to the Edge Server:
143+
```bash
144+
EDGE_SERVER_BASE_URL="https://localhost:60000"
145+
```
146+
147+
* **Start the Development Server**:
148+
Launch the application in development mode using:
149+
```bash
150+
npm run dev -- --host
151+
```
152+
The application will be available at `http://localhost:5173` (or at an IP Address that can be accessible over local network).
153+
154+
## Run the demo
155+
* Open the web app in a browser. It can be on a local machine or remote.
156+
- `http://localhost:5173` will open up the business version of the app.
157+
- `http://localhost:5173/economy` will open up the economy version of the app.
158+
159+
* Disconnect the local machine from the Internet so it cannot access the remote App Services. In this scenario, the Edge Server and the web app are disconnected from Internet.
160+
161+
![](./edge-sample-app-business.png)
162+
163+
* Place some orders via the app.
164+
165+
![](./edge-sample-app-place-order.png)
166+
167+
You will see corresponding requests show up in the console output of the Edge Server, similar to ones below:
168+
```bash
169+
2025-02-24T20:04:08.756-0500 127.0.0.1:61556 PUT /american234.AmericanAirlines.AA234/economyinventory?rev=5-3ad339cd20ca9f04874bf62e45c95eac8bcc0689 -> 201 Created [282.551ms]
170+
2025-02-24T20:04:08.756-0500 (Listener) Obj=/RESTConnection#107/ End of socket connection from 127.0.0.1:61556 (Connection:close)
171+
2025-02-24T20:04:08.769-0500 (Listener) Incoming TLS connection from 127.0.0.1:61558 -- starting handshake
172+
2025-02-24T20:04:08.799-0500 (Listener) Accepted connection from 127.0.0.1:61558
173+
2025-02-24T20:04:08.800-0500 (Listener) {RESTConnection#108}==> litecore::edge_server::RESTConnection from 127.0.0.1:61558 @0x600003d08650
174+
2025-02-24T20:04:08.800-0500 (Listener) Obj=/RESTConnection#108/ Handling GET /american234.AmericanAirlines.AA234/economyinventory
175+
2025-02-24T20:04:09.078-0500 127.0.0.1:61558 GET /american234.AmericanAirlines.AA234/economyinventory -> 200 [278.044ms]
176+
2025-02-24T20:04:09.078-0500 (Listener) Obj=/RESTConnection#108/ End of socket connection from 127.0.0.1:61558 (Connection)
177+
```
178+
* You can also use any HTTP client to fetch a document and verify that it's updated:
179+
180+
```bash
181+
curl --location 'https://localhost:60000/american234.AmericanAirlines.AA234/businessinventory' \
182+
--header 'Authorization: Basic c2VhdHVzZXI6cGFzc3dvcmQ='
183+
```
184+
185+
## Reference Documentation
186+
- [Couchbase Edge Server](https://docs.couchbase.com/couchbase-edge-server/current/get-started/get-started-landing.html)
187+
- [Capella](https://docs.couchbase.com/cloud/get-started/intro.html)

0 commit comments

Comments
 (0)