Skip to content

Commit c6c9717

Browse files
committed
chore: nginx docker server created & port forwarding command updated
1 parent 590ffb6 commit c6c9717

File tree

9 files changed

+100
-15
lines changed

9 files changed

+100
-15
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ MINIO_STORAGE_ENDPOINT="minio:9000"
2929
MINIO_ACCESS_KEY="Fwdk7y1ofPFl8m9Ar8E7"
3030
MINIO_SECRET_KEY="nlbLuKtZPCuzMQck0Q2fdqfWe2mdimCLQNrewzL0"
3131

32-
DOMAIN="localhost:8000"
32+
DOMAIN="localhost:8080"

.envs/.backend.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ MINIO_STORAGE_ENDPOINT="minio:9000"
2929
MINIO_ACCESS_KEY="Fwdk7y1ofPFl8m9Ar8E7"
3030
MINIO_SECRET_KEY="nlbLuKtZPCuzMQck0Q2fdqfWe2mdimCLQNrewzL0"
3131

32-
DOMAIN="localhost:8000"
32+
DOMAIN="localhost:8080"

compose/nginx/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM docker.io/nginx:1.27.0-alpine
2+
3+
COPY ./compose/nginx/default.conf /etc/nginx/conf.d/default.conf

compose/nginx/default.conf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Define an upstream server group named 'backend' for the application backend
2+
upstream backend {
3+
server backend:8000; # Application backend address and port
4+
}
5+
6+
# Define an upstream server group named 'minio' for the MinIO server
7+
upstream minio {
8+
server minio:9000; # MinIO server address and port
9+
}
10+
11+
server {
12+
listen 80; # Listen on port 80 for incoming HTTP requests
13+
server_name bookly; # Add this line to match the hostname used in the SSH tunnel
14+
client_max_body_size 20M; # Set maximum allowed client request body size to 20MB
15+
16+
error_log /var/log/nginx/error.log error; # Main error log file
17+
18+
# Set proxy headers to pass client request information to the backend servers
19+
proxy_set_header Host $http_host; # Changed from $host to $http_host
20+
proxy_set_header X-Real-IP $remote_addr;
21+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
22+
proxy_set_header X-Forwarded-Proto $scheme;
23+
24+
proxy_http_version 1.1; # Use HTTP/1.1 for proxy connections
25+
proxy_buffering off; # Disable proxy buffering
26+
27+
# WebSocket support
28+
proxy_set_header Upgrade $http_upgrade;
29+
proxy_set_header Connection "upgrade";
30+
31+
# Location block for the API
32+
location /api/v1/ {
33+
proxy_pass http://backend/api/v1/; # Proxy requests to the application backend
34+
access_log /var/log/nginx/backend_access.log; # Access log file for the API
35+
error_log /var/log/nginx/backend_error.log error; # Error log file for the API
36+
}
37+
38+
# Location block for the swagger schema
39+
location /swagger/schema/ {
40+
proxy_pass http://backend/api/v1/openapi.json; # Proxy requests to the application backend
41+
access_log /var/log/nginx/swagger_access.log; # Access log file for the swagger schema
42+
}
43+
44+
# Location block for the swagger documentation
45+
location /swagger/redoc/ {
46+
proxy_pass http://backend/api/v1/redoc/; # Proxy requests to the application backend
47+
access_log /var/log/nginx/swagger_access.log; # Access log file for the swagger documentation
48+
}
49+
50+
# Location block for the swagger documentation
51+
location /swagger/docs/ {
52+
proxy_pass http://backend/api/v1/docs/; # Proxy requests to the application backend
53+
access_log /var/log/nginx/swagger_access.log; # Access log file for the swagger documentation
54+
}
55+
56+
# Location block for MinIO storage
57+
location /minio/storage/bookly/ {
58+
proxy_pass http://minio/bookly/; # Proxy requests to the MinIO server
59+
access_log /var/log/nginx/minio_access.log; # Access log file for MinIO
60+
error_log /var/log/nginx/minio_error.log error; # Error log file for MinIO
61+
}
62+
}

docker-compose.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ services:
55
dockerfile: ./compose/backend/Dockerfile
66
image: backend:latest
77
container_name: backend
8-
ports:
9-
- "8000:8000"
108
volumes:
119
- .:/app:z
1210
env_file:
@@ -51,8 +49,6 @@ services:
5149
redis:
5250
image: redis:6
5351
container_name: redis
54-
ports:
55-
- "6379:6379"
5652
volumes:
5753
- redis_data:/data
5854
networks:
@@ -94,7 +90,6 @@ services:
9490
container_name: minio
9591
ports:
9692
- "9090:9090"
97-
- "9000:9000"
9893
volumes:
9994
- minio_data:/data
10095
env_file:
@@ -103,6 +98,22 @@ services:
10398
networks:
10499
- backend_network
105100

101+
nginx:
102+
build:
103+
context: .
104+
dockerfile: ./compose/nginx/Dockerfile
105+
image: nginx:latest
106+
container_name: nginx
107+
ports:
108+
- "8080:80"
109+
depends_on:
110+
- backend
111+
- minio
112+
volumes:
113+
- nginx_data:/var/log/nginx
114+
networks:
115+
- backend_network
116+
106117
networks:
107118
backend_network:
108119
driver: bridge
@@ -112,3 +123,4 @@ volumes:
112123
mailpit_data:
113124
redis_data:
114125
minio_data:
126+
nginx_data:

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ list-deps: $(VENV_DIR)
5454

5555
# Port forwarding command
5656
port-forward:
57-
ssh -R bookly:80:localhost:8000 serveo.net
57+
ssh -R bookly:80:localhost:8080 serveo.net
5858

5959
# Group Alembic related commands
6060
alembic-commands: upgrade-db downgrade-db create-migration

pkg/middleware.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ async def custom_logging(request: Request, call_next):
3232

3333
app.add_middleware(
3434
TrustedHostMiddleware,
35-
allowed_hosts=[
36-
"localhost",
37-
"127.0.0.1",
38-
"0.0.0.0",
39-
],
35+
allowed_hosts=["bookly.serveo.net", "localhost"],
4036
)
4137

4238
app.add_middleware(
4339
CORSMiddleware,
44-
allow_origins=["*"],
40+
allow_origins=["bookly.serveo.net", "localhost"],
4541
allow_methods=["*"],
4642
allow_headers=["Content-Type", "Authorization"],
4743
allow_credentials=True,

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ Bookly is an innovative online platform designed for book lovers to connect and
2424
- **Token Blacklisting:** Ensures that tokens are invalidated after logout or expiration.
2525
- **Celery Integration for Background Tasks:** For sending emails and clearing expired tokens and logs.
2626

27+
### Profile
28+
29+
- **Auto User Profile Creation**: User profile is created on user verification.
30+
- **User Profile Update**: Users can update their profile information.
31+
- **Avatar Image Upload**: Users can upload and image through form data to be used as avatar image.
32+
2733
## Technologies Used
2834

2935
- **Backend Framework:** FastAPI
3036
- **Database:** PostgreSQL
3137
- **Asynchronous ORM:** SQLModel
3238
- **Task Queue:** Celery
3339
- **Broker:** Redis
40+
- **Storage:** MinIO
3441
- **Other Libraries:** Pydantic, Alembic, etc.
3542

3643
## Installation
@@ -77,6 +84,11 @@ This command will build the necessary services and start the application, includ
7784
- **Reset Password:** `POST /auth/reset-password/{password_reset_token}`
7885
- **Get Logged-in User:** `GET /auth/me`
7986

87+
### Profile Endpoints
88+
89+
- **Update Profile:** `PATCH /profile/update-profile`
90+
- **Update Avatar Image**: `PATCH /profile/update-avatar`
91+
8092
## API Documentation
8193

8294
You can find the full API documentation at `http://localhost:8000/api/v1/docs`, generated using Swagger UI.

src/profile/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def update_user_avatar(
7373
avatar_image.content_type,
7474
)
7575

76-
file_url = f"http://{Config.MINIO_STORAGE_ENDPOINT}/{Config.MINIO_STORAGE_BUCKET}/{avatar_image_file_name}"
76+
file_url = f"http://{Config.DOMAIN}/minio/storage/{Config.MINIO_STORAGE_BUCKET}/{avatar_image_file_name}"
7777
await user_profile_service.update_user_profile_avatar(
7878
user_profile, file_url, session
7979
)

0 commit comments

Comments
 (0)