Skip to content

Commit 6a90e86

Browse files
neon-balconygitbook-bot
authored andcommitted
GitBook: [#50] add docs: 'How to access local database or API'
1 parent d41cdc8 commit 6a90e86

File tree

10 files changed

+65
-9
lines changed

10 files changed

+65
-9
lines changed
81.2 KB
Loading
490 KB
Loading
188 KB
Loading
84.9 KB
Loading

docs/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Table of contents
22

33
* [Openblocks overview](README.md)
4-
* [Self-hosting](self-hosting.md)
4+
* [Self-hosting](self-hosting/README.md)
5+
* [Access local database or API](self-hosting/access-local-database-or-api.md)
56
* [Security](security.md)
67

78
## Data sources

docs/build-apps/event-handlers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In Openblocks, event handlers are responsible for collecting and processing events from components and queries, and executing subsequent actions. For example, for a **Button** component, you can add an event handler to trigger the **Run query** action **** in response to the button **Click** event.
44

5-
<figure><img src="../.gitbook/assets/image (8).png" alt=""><figcaption></figcaption></figure>
5+
<figure><img src="../.gitbook/assets/image (19).png" alt=""><figcaption></figcaption></figure>
66

77
Set event handlers wisely to provide a reactive and responsive user experience (UX). For example, triggering a **get-all** query after **insert-new-data** query finishes enables table automatically refresh.
88

@@ -32,7 +32,7 @@ Running a query can result in success or failure, so queries have two events: **
3232

3333
There are a number of event handler actions available in Openblocks for handling different scenarios. Set them in the **Action** dropdown list in an event handler.
3434

35-
![](<../.gitbook/assets/image (9).png>)
35+
![](<../.gitbook/assets/image (1).png>)
3636

3737
{% hint style="info" %}
3838
See [advanced](event-handlers.md#advanced) on this page to know advanced settings.
@@ -48,7 +48,7 @@ Trigger the selected query.
4848

4949
To control a component, select a component in the **Component** dropdown list and call one of its methods in the **Method** dropdown list.
5050

51-
![](<../.gitbook/assets/image (29).png>)
51+
![](<../.gitbook/assets/image (17).png>)
5252

5353
### Set temporary state
5454

docs/data-sources/data-source-basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Follow the steps below:
1515
1. Click **Data Sources** on Openblocks homepage.
1616
2. Click **New data source** on the upper right. This permission is restricted to workspace admins and developers.
1717

18-
<figure><img src="../.gitbook/assets/image (31).png" alt=""><figcaption></figcaption></figure>
18+
<figure><img src="../.gitbook/assets/image (12).png" alt=""><figcaption></figcaption></figure>
1919
3. Select the database or API type you need to connect.
2020

2121
<figure><img src="../.gitbook/assets/image (32).png" alt=""><figcaption></figcaption></figure>

docs/queries/query-basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Queries support you to read data from or write data to your data sources. You ca
66

77
You can connect to a data source that was already in your data source library or create a new one. For detailed information, see [Data source basics](../data-sources/data-source-basics.md).
88

9-
<figure><img src="../.gitbook/assets/image (12).png" alt=""><figcaption></figcaption></figure>
9+
<figure><img src="../.gitbook/assets/image (31).png" alt=""><figcaption></figcaption></figure>
1010

1111
## Create a query
1212

docs/self-hosting.md renamed to docs/self-hosting/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ Follow the steps below:
3232
2. Start the Docker container by running this command: `docker-compose up -d` ;\
3333
The docker image, about 400 MB, is downloaded during the initial start-up.
3434

35-
<figure><img src=".gitbook/assets/download-ce.png" alt=""><figcaption></figcaption></figure>
35+
<figure><img src="../.gitbook/assets/download-ce.png" alt=""><figcaption></figcaption></figure>
3636

3737
After downloading, it usually takes less than 30 seconds to start the service.
3838
3. Check the logs by running this command: `docker logs -f openblocks` ;\
3939
When you see `frontend`, `backend`, `redis`, and `mongo` `entered the RUNNING state`, the Openblocks service has officially started:\
4040

4141

42-
<figure><img src=".gitbook/assets/check-logs-ce.png" alt=""><figcaption></figcaption></figure>
42+
<figure><img src="../.gitbook/assets/check-logs-ce.png" alt=""><figcaption></figcaption></figure>
4343

4444
### Update
4545

@@ -79,4 +79,4 @@ docker run -d --name openblocks -p 3000:3000 -v "$PWD/stacks:/openblocks-stacks"
7979

8080
Visit **http://localhost:3000** and click **Sign up**. Openblocks will automatically create a workspace for you, then you can start building your apps and invite members to your workspace.
8181

82-
<figure><img src=".gitbook/assets/after-deployment.png" alt=""><figcaption></figcaption></figure>
82+
<figure><img src="../.gitbook/assets/after-deployment.png" alt=""><figcaption></figcaption></figure>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Access local database or API
2+
3+
By default, docker-hosted instances uses a [bridge network](https://docs.docker.com/network/bridge/), which does not support access to service on the host via `127.0.0.1` or `localhost`. Here we take PostgreSQL as an example and show you how to access local API or database in different operating systems (OS) for docker-hosted Openblocks.
4+
5+
## Preparation
6+
7+
Assume that a Postgres service is ready on your local host with port `5432`. Confirm that access to the Postgres service functions well.
8+
9+
<figure><img src="../.gitbook/assets/access-local-pre.png" alt=""><figcaption></figcaption></figure>
10+
11+
## How to access local database or API
12+
13+
{% tabs %}
14+
{% tab title="Linux" %}
15+
1. Enter `ifconfig docker0` in the terminal, and verify the IP configuration of Docker's virtual bridge (VB).
16+
17+
<figure><img src="../.gitbook/assets/access-local-linux.png" alt=""><figcaption></figcaption></figure>
18+
19+
Having set up Docker, the OS would automatically create `docker0` with the IP address `172.17.0.1` (by default), through which the Docker service communicates with the host.
20+
2. Enter the same IP address into Openblocks to configure the Postgres data source (`172.17.0.1` in this example, but use the actual IP address displayed on your terminal in real case).
21+
22+
23+
24+
<figure><img src="../.gitbook/assets/access-local-linux-2.png" alt=""><figcaption></figcaption></figure>
25+
26+
{% hint style="warning" %}
27+
On some OS (such as Ubuntu), port access might be blocked by the firewall. To solve that, configure in the following steps:
28+
29+
1. Stop the firewall from blocking access from **docker0** by typing in the terminal:\
30+
<mark style="background-color:yellow;">**`iptables -A INPUT -p tcp -i docker0 --dport YOUR_DB_PORT -j ACCEPT`**</mark>\
31+
`Note: In this case`Here we use Postgres port <mark style="background-color:yellow;">**`5432`**</mark> for <mark style="background-color:yellow;">**`YOUR_DB_PORT`**</mark>, and you should replace it with your own.
32+
2. Save the firewall configuration by typing in the terminal:\
33+
<mark style="background-color:yellow;">**`iptables-save > /etc/iptables.up.rules`**</mark>
34+
{% endhint %}
35+
{% endtab %}
36+
37+
{% tab title="Windows & Mac" %}
38+
On Windows and masOS, Docker does not create the virtual bridge `docker0`. Then the following DNS is helpful to resolve the host IP:
39+
40+
```
41+
host.docker.internal
42+
```
43+
44+
In Openblocks, configure the Postgres data source as the following figure shows:
45+
46+
47+
48+
<figure><img src="../.gitbook/assets/access-local-win-mac.png" alt=""><figcaption></figcaption></figure>
49+
{% endtab %}
50+
{% endtabs %}
51+
52+
53+
54+
55+

0 commit comments

Comments
 (0)