Skip to content

Commit 4ec30e0

Browse files
committed
ADD CORS instruction
1 parent fbee590 commit 4ec30e0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/3_BuildPostgreSQL/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ docker images
140140
docker run -p 5432:5432 --rm --detach --interactive --name custom-database-layer -d custom-database-layer:2.0
141141
```
142142
143-
Make sure to test connection again. We are successful! Now, let’s move onto the next step.
143+
Make sure to test connection again. We are successful!
144+
145+
Now, let’s move onto the next step.
146+
144147
145148
[Prev - Before getting started](../2_BeforeGettingStarted/README.md) | [Next - Deploy the PostgreSQL package to GitHub Packages](../4_StoringPostgreSQLImageRegistry/README.md)

docs/5_BuildPythonDjango/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,37 @@ You can verify the result by either calling our retrieve-data-db.py or checking
143143

144144
![Verify Result](./images/19_SuccessDB.jpg)
145145

146+
Before proceeding further, we need to make an adustment to our Python Django server so it can handle CORS exception. This is necessary because our API endpoint might not be accessible to our ReactJS front layer. We can do this by installing a library called `django-cors-headers` and adding it to our `INSTALLED_APPS` in `myproject/settings.py`.
147+
148+
Run the following command:
149+
150+
```bash
151+
pip install django-cors-headers
152+
```
153+
154+
![Install CORS](./images/20_InstallCORS.jpg)
155+
156+
Then, add `corsheaders` to `INSTALLED_APPS` in `myproject/settings.py`.
157+
158+
![Add CORS](./images/21_AddCORS_installed.jpg)
159+
160+
You also need to add `corsheaders.middleware.CorsMiddleware` to `MIDDLEWARE` in `myproject/settings.py`.
161+
162+
![Add to middlewae](./images/22_AddCORS_middleware.jpg)
163+
164+
Next, add the following to `myproject/settings.py`. I added at the end of file.
165+
166+
```python
167+
CORS_ORIGIN_ALLOW_ALL = False
168+
CORS_ORIGIN_WHITELIST = (
169+
'http://localhost:3000',
170+
)
171+
```
172+
173+
![Add origins](./images/23_AddCORS_origin.jpg)
174+
175+
Then, restart your Python Django server.
176+
146177
Awesome. Now, we are ready to move onto our final step to build a front layer using ReactJS.
147178

148179
[Prev - Deploy the PostgreSQL package to GitHub Packages](../4_StoringPostgreSQLImageRegistry/README.md) | [Next - Build a ReactJS front layer](../6_BuildReactJS/README.md)

0 commit comments

Comments
 (0)