Skip to content

Commit

Permalink
Merge: nginx 설정 추가, product serializer 수정
Browse files Browse the repository at this point in the history
[Feature/nginx-websocket] nginx 설정 추가, product serializer 수정
  • Loading branch information
yyysolhhh authored May 29, 2024
2 parents ec6a11b + 0b4791f commit ec0e65c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
27 changes: 17 additions & 10 deletions apps/product/serializers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# from rest_framework import serializers
# from apps.product.models import Product, ProductImage, ProductCategory, StyleCategory
# from apps.user.models import Account
import logging
from typing import Any

from django.db import transaction
from rest_framework import serializers
from rest_framework.fields import ReadOnlyField
from rest_framework.utils.serializer_helpers import ReturnDict

from apps.category.models import Style
from apps.category.models import Category, Style
from apps.like.models import Like
from apps.product.models import Product, ProductImage, RentalHistory
from apps.user.serializers import UserInfoSerializer
Expand All @@ -32,13 +27,18 @@ class Meta:


class ProductSerializer(serializers.ModelSerializer[Product]):
# lender = ReadOnlyField(source="lender.nickname")
lender = UserInfoSerializer(read_only=True)
# rental_history = RentalHistorySerializer(many=True, read_only=True)
# images = serializers.SerializerMethodField()
images = ProductImageSerializer(many=True, read_only=True)
is_liked = serializers.SerializerMethodField()

# product_category = serializers.PrimaryKeyRelatedField(queryset=Category.objects.all(), write_only=True)
# category_name = serializers.ReadOnlyField(source="product_category.name")
product_category = serializers.SlugRelatedField(slug_field="name", queryset=Category.objects.all())

# styles = serializers.PrimaryKeyRelatedField(queryset=Style.objects.all(), many=True, write_only=True)
# style_names = serializers.SerializerMethodField(read_only=True)
styles = serializers.SlugRelatedField(many=True, slug_field="name", queryset=Style.objects.all())

class Meta:
model = Product
fields = (
Expand All @@ -55,7 +55,9 @@ class Meta:
"size",
"views",
"product_category",
# "category_name",
"styles",
# "style_names",
"status",
"amount",
"region",
Expand All @@ -64,10 +66,15 @@ class Meta:
"images",
"likes",
"is_liked",
# "rental_history",
)
read_only_fields = ("created_at", "updated_at", "views", "lender", "status", "likes", "is_liked")

# def get_category_name(self, obj: Product) -> str:
# return obj.product_category.name

# def get_style_names(self, obj: Product) -> list[str]:
# return [style.name for style in obj.styles.all()]

def get_is_liked(self, obj: Product) -> bool:
user = self.context["request"].user
if user.is_authenticated:
Expand Down
1 change: 0 additions & 1 deletion config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@

# 커스텀 설정 # TODO
FRONT_CONFIRM_URL = env("FRONT_CONFIRM_URL")
GOOGLE_OAUTH2_URL = env("GOOGLE_OAUTH2_URL")
CONFIRM_CODE_LENGTH = env("CONFIRM_CODE_LENGTH")
EMAIL_CODE_TIMEOUT = env("EMAIL_CODE_TIMEOUT")
DJANGO_SUPERUSER_EMAIL = env("DJANGO_SUPERUSER_EMAIL")
Expand Down
1 change: 0 additions & 1 deletion config/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@

# 커스텀 설정 # TODO
FRONT_CONFIRM_URL = ENV["FRONT_CONFIRM_URL"]
GOOGLE_OAUTH2_URL = ENV["GOOGLE_OAUTH2_URL"]
CONFIRM_CODE_LENGTH = ENV["CONFIRM_CODE_LENGTH"]
EMAIL_CODE_TIMEOUT = ENV["EMAIL_CODE_TIMEOUT"]
DJANGO_SUPERUSER_EMAIL = ENV["DJANGO_SUPERUSER_EMAIL"]
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ python manage.py collectstatic --noinput
python manage.py shell < tools/create_superuser.py
#python manage.py runserver 0.0.0.0:80

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

Expand Down
9 changes: 6 additions & 3 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
# location /static/ {
# alias /backend/static/;
# }
}
40 changes: 40 additions & 0 deletions nginx/nginx_ws.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
server {
listen 80;
server_name api.coatycloset.store;

location / {
return 301 https://$server_name$request_uri;
}
}

server {
listen 443 ssl;
server_name api.coatycloset.store;

ssl_certificate /etc/letsencrypt/live/api.coatycloset.store/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.coatycloset.store/privkey.pem;

client_max_body_size 100M;

access_log /var/log/nginx/443_access.log;
error_log /var/log/nginx/443_error.log;

location /api/ {
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws/ {
proxy_pass http://websocket:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

0 comments on commit ec0e65c

Please sign in to comment.