Skip to content

Commit ec0e65c

Browse files
authored
Merge: nginx 설정 추가, product serializer 수정
[Feature/nginx-websocket] nginx 설정 추가, product serializer 수정
2 parents ec6a11b + 0b4791f commit ec0e65c

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

apps/product/serializers.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
# from rest_framework import serializers
2-
# from apps.product.models import Product, ProductImage, ProductCategory, StyleCategory
3-
# from apps.user.models import Account
41
import logging
52
from typing import Any
63

74
from django.db import transaction
85
from rest_framework import serializers
9-
from rest_framework.fields import ReadOnlyField
10-
from rest_framework.utils.serializer_helpers import ReturnDict
116

12-
from apps.category.models import Style
7+
from apps.category.models import Category, Style
138
from apps.like.models import Like
149
from apps.product.models import Product, ProductImage, RentalHistory
1510
from apps.user.serializers import UserInfoSerializer
@@ -32,13 +27,18 @@ class Meta:
3227

3328

3429
class ProductSerializer(serializers.ModelSerializer[Product]):
35-
# lender = ReadOnlyField(source="lender.nickname")
3630
lender = UserInfoSerializer(read_only=True)
37-
# rental_history = RentalHistorySerializer(many=True, read_only=True)
38-
# images = serializers.SerializerMethodField()
3931
images = ProductImageSerializer(many=True, read_only=True)
4032
is_liked = serializers.SerializerMethodField()
4133

34+
# product_category = serializers.PrimaryKeyRelatedField(queryset=Category.objects.all(), write_only=True)
35+
# category_name = serializers.ReadOnlyField(source="product_category.name")
36+
product_category = serializers.SlugRelatedField(slug_field="name", queryset=Category.objects.all())
37+
38+
# styles = serializers.PrimaryKeyRelatedField(queryset=Style.objects.all(), many=True, write_only=True)
39+
# style_names = serializers.SerializerMethodField(read_only=True)
40+
styles = serializers.SlugRelatedField(many=True, slug_field="name", queryset=Style.objects.all())
41+
4242
class Meta:
4343
model = Product
4444
fields = (
@@ -55,7 +55,9 @@ class Meta:
5555
"size",
5656
"views",
5757
"product_category",
58+
# "category_name",
5859
"styles",
60+
# "style_names",
5961
"status",
6062
"amount",
6163
"region",
@@ -64,10 +66,15 @@ class Meta:
6466
"images",
6567
"likes",
6668
"is_liked",
67-
# "rental_history",
6869
)
6970
read_only_fields = ("created_at", "updated_at", "views", "lender", "status", "likes", "is_liked")
7071

72+
# def get_category_name(self, obj: Product) -> str:
73+
# return obj.product_category.name
74+
75+
# def get_style_names(self, obj: Product) -> list[str]:
76+
# return [style.name for style in obj.styles.all()]
77+
7178
def get_is_liked(self, obj: Product) -> bool:
7279
user = self.context["request"].user
7380
if user.is_authenticated:

config/settings/local.py

-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209

210210
# 커스텀 설정 # TODO
211211
FRONT_CONFIRM_URL = env("FRONT_CONFIRM_URL")
212-
GOOGLE_OAUTH2_URL = env("GOOGLE_OAUTH2_URL")
213212
CONFIRM_CODE_LENGTH = env("CONFIRM_CODE_LENGTH")
214213
EMAIL_CODE_TIMEOUT = env("EMAIL_CODE_TIMEOUT")
215214
DJANGO_SUPERUSER_EMAIL = env("DJANGO_SUPERUSER_EMAIL")

config/settings/prod.py

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151

152152
# 커스텀 설정 # TODO
153153
FRONT_CONFIRM_URL = ENV["FRONT_CONFIRM_URL"]
154-
GOOGLE_OAUTH2_URL = ENV["GOOGLE_OAUTH2_URL"]
155154
CONFIRM_CODE_LENGTH = ENV["CONFIRM_CODE_LENGTH"]
156155
EMAIL_CODE_TIMEOUT = ENV["EMAIL_CODE_TIMEOUT"]
157156
DJANGO_SUPERUSER_EMAIL = ENV["DJANGO_SUPERUSER_EMAIL"]

entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ python manage.py collectstatic --noinput
1212
python manage.py shell < tools/create_superuser.py
1313
#python manage.py runserver 0.0.0.0:80
1414

15-
#gunicorn --bind 0.0.0.0:80 config.wsgi:application
15+
#gunicorn --bind 0.0.0.0:8001 config.wsgi:application
1616
#uvicorn config.asgi:application --workers 4
1717
#gunicorn config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
1818

nginx/nginx.conf

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ server {
2525
proxy_set_header X-Real-IP $remote_addr;
2626
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2727
proxy_set_header X-Forwarded-Proto $scheme;
28+
proxy_http_version 1.1;
29+
proxy_set_header Upgrade $http_upgrade;
30+
proxy_set_header Connection "upgrade";
31+
32+
proxy_read_timeout 86400s;
33+
proxy_send_timeout 86400s;
2834
}
29-
# location /static/ {
30-
# alias /backend/static/;
31-
# }
3235
}

nginx/nginx_ws.conf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
server {
2+
listen 80;
3+
server_name api.coatycloset.store;
4+
5+
location / {
6+
return 301 https://$server_name$request_uri;
7+
}
8+
}
9+
10+
server {
11+
listen 443 ssl;
12+
server_name api.coatycloset.store;
13+
14+
ssl_certificate /etc/letsencrypt/live/api.coatycloset.store/fullchain.pem;
15+
ssl_certificate_key /etc/letsencrypt/live/api.coatycloset.store/privkey.pem;
16+
17+
client_max_body_size 100M;
18+
19+
access_log /var/log/nginx/443_access.log;
20+
error_log /var/log/nginx/443_error.log;
21+
22+
location /api/ {
23+
proxy_pass http://backend:8000;
24+
proxy_set_header Host $host;
25+
proxy_set_header X-Real-IP $remote_addr;
26+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27+
proxy_set_header X-Forwarded-Proto $scheme;
28+
}
29+
30+
location /ws/ {
31+
proxy_pass http://websocket:8001;
32+
proxy_http_version 1.1;
33+
proxy_set_header Upgrade $http_upgrade;
34+
proxy_set_header Connection "upgrade";
35+
proxy_set_header Host $host;
36+
proxy_set_header X-Real-IP $remote_addr;
37+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
38+
proxy_set_header X-Forwarded-Proto $scheme;
39+
}
40+
}

0 commit comments

Comments
 (0)