Skip to content

Commit 3b98a98

Browse files
committed
nginx
1 parent e30dd17 commit 3b98a98

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<h1 align="center">
22
React-ChatGPT
33
</h1>
4+
45
<p align="center">
56
<strong>Simple Full-Stack Summarizer based on ChatGPT</strong>
67
</p>
78

9+
[![CodeQL](https://github.com/frankling2020/react-chatgpt/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/frankling2020/react-chatgpt/actions/workflows/github-code-scanning/codeql)
10+
811
## Simple Summarizer
912
### Description
1013
<p>
1114
It contains a React-based summarizer built with ChatGPT whose primary purpose of the application is to generate a summary of paragraphs with highlighting of the relevant keywords. It aims to facilitate the comprehension of the original text and to enhance user trust in the generated summary.
1215
</p>
1316
<p>
14-
<b>Tools</b>: <em>Docker, OpenAI, ReactJS, Flask (gunicorn + gevent), Celery (Redis)</em>
17+
<b>Tools</b>: <em>Docker, OpenAI, ReactJS, Flask (gunicorn + gevent), Celery (Redis), Nginx</em>
1518
</p>
1619

1720
---
@@ -24,7 +27,7 @@
2427
- **Gevent**: it will allow web application to scale to potentially thousands of concurrent requests on a single process. It mainly replaces blocking parts with compatible cooperative counterparts from gevent package by "monkey patching". It uses epoll or kqueue or libevent for highly scalable non-blocking I/O.
2528
- **Celery**: Celery is a powerful and robust distributed task queue system that enables asynchronous task execution, scheduling, and distributed work processing. Celery supports distributing tasks across multiple workers, allowing applications to scale horizontally by adding more Celery workers as needed.
2629
- **Redis**: Redis provides a fast, lightweight, and efficient message queue system, making it suitable for handling large volumes of tasks and ensuring reliable task delivery.
27-
- **Nginx (TO-DO)**: NGINX is well known as a high‑performance load balancer, cache, and web server.
30+
- **Nginx**: NGINX is well known as a high‑performance load balancer, cache, and web server. It is often preferred over Linux Virtual Server (LVS) for load balancing and reverse proxying. It is a full-featured web server and reverse proxy, providing a complete solution with built-in load balancing, caching, access control, and other features. LVS, on the other hand, is primarily focused on load balancing and requires additional components for other functionalities.
2831

2932
---
3033

@@ -79,13 +82,22 @@ You can start the broker to make the web appliaction more scalable with the comm
7982
The detailed configuration is under `backend/celeryconfig.py`
8083

8184

82-
#### Development with Dokcer
85+
#### Load Balance: Nginx (to-do)
86+
Please see the configuration in `nginx.conf`. Run with
87+
- `nginx -g daemon off`
88+
89+
90+
#### Development with Docker
8391
Docker is a good tool to deploy applications in different platforms. Here you can see we have `Dockerfile` in both `frontend/` and `backend/` folders and `docker-compose.yaml` in the directory. So, you can directly use the command `docker-compose -d up` with `docker` installed in your computer. I would recommend you to use Docker Desktop which can inspect the containers with GUI shown below.
8492

93+
8594
<div align="center">
8695
<img src="examples/docker-impl.png" style="width:70%">
96+
<img src="examples/nginx.png" style="width:70%">
8797
</div>
8898

99+
We can choose either Node or Nginx as the web server. The top figure is with Node, while the bottom figure is with Nginx. It is worth noticing that with Nginx, the frontend server with Node only need to complete the compilation.
100+
89101
The following figure shows the success deployment and some console log for your debegging in the web inspection mode.
90102
<div align="center">
91103
<img src="examples/inspection.png" style="width:90%">
@@ -118,6 +130,7 @@ The following figure shows the success deployment and some console log for your
118130
- [MDN react](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_components#defining_our_first_component)
119131
- [Gunicorn with Flask](https://flask.palletsprojects.com/en/2.3.x/deploying/gunicorn/)
120132
- [Flask with Celery](https://flask.palletsprojects.com/en/2.3.x/patterns/celery/)
133+
- [Nginx: Beginner's Guide](https://nginx.org/en/docs/beginners_guide.html)
121134

122135

123136
## Getting Started with Create React App (Default React Documentation)

backend/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from flask_cors import CORS
1212
from celery.result import AsyncResult
1313
from celery_task import fetch_summary_from_openai
14+
import socket
1415

1516

1617
app = Flask(__name__)
@@ -41,7 +42,9 @@ def fetch_summary():
4142
api = request.json["api"]
4243
query = request.json["query"]
4344
task = fetch_summary_from_openai.delay(api, query)
44-
return {"task_id": task.id}
45+
hostname = socket.gethostname()
46+
host_ip = socket.gethostbyname(hostname)
47+
return {"task_id": task.id, "host_ip": host_ip, "hostname": hostname}
4548

4649

4750
if __name__ == "__main__":

docker-compose.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ services:
55
build: ./frontend
66
environment:
77
- REACT_APP_BACKEND_URL=http://backend:8000
8-
# volumes:
9-
# - react_build:/app/build
10-
ports:
11-
- "3000:3000"
8+
volumes:
9+
- react_build:/app/build
10+
# ports:
11+
# - "3000:3000"
1212
backend:
1313
build: ./backend
1414
environment:
@@ -29,13 +29,13 @@ services:
2929
image: redis
3030
# ports:
3131
# - "6379:6379"
32-
# nginx:
33-
# image: nginx
34-
# volumes:
35-
# - ./nginx.conf:/etc/nginx/conf.d/default.conf
36-
# - react_build:/app/build
37-
# ports:
38-
# - "8001:80"
32+
nginx:
33+
image: nginx
34+
volumes:
35+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
36+
- react_build:/app/build
37+
ports:
38+
- "8001:80"
3939

40-
# volumes:
41-
# react_build:
40+
volumes:
41+
react_build:

examples/nginx.png

196 KB
Loading

frontend/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ RUN npm install
66
ENV PATH /app/node_modules/.bin:$PATH
77
COPY . .
88
RUN npm run build
9-
CMD [ "npm", "run", "start"]
9+
10+
# No need to run the server here, it will be run by the nginx server
11+
# CMD [ "npm", "run", "start"]

nginx.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
upstream backend {
1+
upstream flask_server {
22
server backend:8000;
33
}
44

@@ -11,7 +11,8 @@ server {
1111
root /app/build;
1212
}
1313

14-
location /submit {
15-
proxy_pass http://backend;
14+
location /api {
15+
proxy_pass http://flask_server;
16+
rewrite ^/api/(.*) /$1 break;
1617
}
1718
}

0 commit comments

Comments
 (0)