Skip to content

Commit

Permalink
Merge pull request #54 from 2023-Winter-techeer-Bootcamp-Team-E/fix/#52
Browse files Browse the repository at this point in the history
fix: nignx cookie issue
  • Loading branch information
dongwooooooo authored Jan 14, 2024
2 parents fb27e55 + fef2c69 commit 8f7a93f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 30 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ services:
- frontend
expose:
- '80'
networks:
- haru
# - '443'
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
networks:
Expand Down
19 changes: 19 additions & 0 deletions haruProject/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@
CORS_ALLOW_CREDENTIALS = True
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]

CORS_ALLOWED_ORIGINS = [
"http://localhost:8080",
"http://127.0.0.1",
"http://localhost:file",
]

CORS_ORIGIN_ALLOW_ALL = True

SESSION_COOKIE_SAMESITE = None

# SESSION_COOKIE_DOMAIN = "founderslooking.com"

#SESSION_COOKIE_SECURE = False

CSRF_TRUSTED_ORIGINS = ["http://localhost", "http://*.127.0.0.1"]

INTERNAL_IPS = [
"127.0.0.1",
]
ROOT_URLCONF = 'config.urls'

TEMPLATES = [
Expand Down
2 changes: 1 addition & 1 deletion haruProject/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.urls import path, include
from diary.views import DiariesGet,DiariesPost
from diary.views import Diaries
from harucalendar.views import HarucalendarView
from django.contrib import admin
from django.urls import path, re_path, include
Expand Down
9 changes: 5 additions & 4 deletions haruProject/diary/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path
from .views import DiariesGet,DiariesPost, DiaryManager, DiariesPut, DiaryStickerManager
from .views import DiaryManager, DiaryTextBoxManager, DiaryStickerManager, Diaries


urlpatterns = [
path('', DiariesPost.as_view(), name='diaries'),
path('', Diaries.as_view(), name='diaries'),
path('link/<int:diary_id>', DiaryManager.as_view(), name='diary_manager'),
path('<int:diary_id>', DiariesGet.as_view()),
path('save', DiariesPut.as_view(), name='diary_textbox_manager'),
path('<int:diary_id>', Diaries.as_view()),
path('textboxes', DiaryTextBoxManager.as_view(), name='diary_textbox_manager'),
path('stickers', DiaryStickerManager.as_view(), name='diary_sticker_manager')
]
59 changes: 36 additions & 23 deletions haruProject/diary/views.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
from django.core.exceptions import ObjectDoesNotExist
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import api_view
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.generics import get_object_or_404
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response

from member.models import Member
from static.models import StaticBgImage
from .models import Diary, DiaryTextBox

from .models import Diary
from .serializers import (DiaryDetailSerializer, DiarySnsLinkSerializer,
DiaryCreateSerializer,
DiaryStickerCreateSerializer, DiaryTextBoxCreateSerializer)

DiaryCreateSerializer, DiaryTextBoxCreateSerializer,
DiaryStickerCreateSerializer, DiaryUpdateSerializer)
from harucalendar.models import Harucalendar
from harucalendar.serializer import HarucalendarCreateSerializer
from .utils import extract_top_keywords, generate_sticker_images
from botocore.exceptions import NoCredentialsError
import boto3
import uuid
import time
import requests

from .swaggerserializer import DiaryGetRequestSerializer, DiaryGetResponseSerializer, DiaryLinkGetResponseSerializer, \
DiaryTextBoxPutRequestSerializer, DiaryTextBoxPutResponseSerializer, DiaryStickerRequestSerializer, \
from .swaggerserializer import DiaryGetResponseSerializer, DiaryLinkGetResponseSerializer, \
DiaryTextBoxPutRequestSerializer, DiaryStickerRequestSerializer, \
DiaryStickerGetResponseSerializer, SwaggerDiaryCreateRequestSerializer, SwaggerDiaryCreateResponseSerializer


class DiariesGet(APIView):
# Create your views here.

class Diaries(APIView):
# 일기장 조회

@swagger_auto_schema(
operation_description="일기에 연동 된 텍스트박스,스티커 등등 출력<br>1.해당달에 존재 하는 전반적인 일기 목록은 캘린더 조회에서 확인<br> 2.일기의 세부 내용(스티커,텍스트박스 등) 출력",
operation_summary="일기 조회",
Expand All @@ -46,18 +43,17 @@ def get(self, request, diary_id):
except ObjectDoesNotExist:
return Response({"error": "diary does not exist"}, status=status.HTTP_404_NOT_FOUND)

@staticmethod
@swagger_auto_schema(request_body=SwaggerDiaryCreateRequestSerializer, responses={200: SwaggerDiaryCreateResponseSerializer})
def post(request):
# 쿠키로 받아서 쓸거임 claendar id, member-id
calendar_id = request.session.get('calendar_id')
member_id = request.session.get('member_id')

if member_id is None:
return Response({'error': '로그인이 필요합니다.'}, status=status.HTTP_400_BAD_REQUEST)
diary_date = request.data.get('diary_date')

class DiariesPost(APIView):
@swagger_auto_schema(
operation_description="1.캘린더가 없는상태면 캘린더 생성 후 다이어리 저장,<br>2.캘린더 존재 시 다이어리 바로 저장",
operation_summary="일기초안 생성",
request_body=SwaggerDiaryCreateRequestSerializer, responses={200: SwaggerDiaryCreateResponseSerializer})
def post(self, request):
calendar_id = request.data.get('calendar_id')
member_id = request.data.get('member_id')
year_month = request.data.get('year_month')
day = request.data.get('day')
if calendar_id is None:
member_instance = get_object_or_404(Member, member_id=member_id)
calendar_serializer = HarucalendarCreateSerializer(data={'year_month': year_month})
Expand Down Expand Up @@ -157,6 +153,23 @@ def request_manager(request):
# return Response(diary_serializer.data, status=status.HTTP_400_BAD_REQUEST)


# 일기장 최종 저장

# 일기장 링크공유
class DiaryManager(APIView):
@swagger_auto_schema(
responses={200: DiaryLinkGetResponseSerializer})
def get(self, request, diary_id):

found_diary = Diary.objects.get(diary_id=diary_id)

try:
sns_link = DiarySnsLinkSerializer(found_diary)
return Response(status=status.HTTP_200_OK, data=sns_link.data)
except ObjectDoesNotExist:
return Response({"error": "diary snsLink does not exist"}, status=status.HTTP_404_NOT_FOUND)


class DiariesPut(APIView):
@swagger_auto_schema(operation_description="일기 최종 저장",
operation_summary="기존 만들어진 일기에 일기 텍스트 박스 및 스티커 정보 저장",
Expand Down
1 change: 1 addition & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ server {
# default_type application/octet-stream;
# include /etc/nginx/mime.types;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie "$http_cookie; ip=$remote_addr";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
Expand Down

0 comments on commit 8f7a93f

Please sign in to comment.