Skip to content

Commit 023ef79

Browse files
Merge pull request #53 from druling/cors_fix
fixing cors error
2 parents a73409a + 4b0d309 commit 023ef79

File tree

9 files changed

+38
-11
lines changed

9 files changed

+38
-11
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PORT=3000
2-
DEV=True
2+
ENV=dev
3+
DEBUG=True
34
ALLOWED_HOSTS=localhost,127.0.0.1,
45

56
# Google OAuth Credentials

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build, Push, and Deploy
33
on:
44
push:
55
branches:
6-
- adding_actions
6+
- cors_fix
77

88
jobs:
99
build-and-push:

build/docker/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1414
# Set the working directory in the container
1515
WORKDIR /app
1616

17+
# Ensure required directories exist
18+
RUN mkdir -p /app/static /app/media
19+
1720
# Copy the requirements file to the container
1821
COPY ../../requirements.txt /app/
1922

commons/clients/boto_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.conf import settings
44

55

6-
def boto_client(service=None):
6+
def boto_client(service=None, config=None):
77
if service is None:
88
raise ValueError("Service name is required")
99

@@ -15,4 +15,6 @@ def boto_client(service=None):
1515
)
1616
else:
1717
# Production AWS configuration
18-
return boto3.client(service, region_name=settings.AWS_DEFAULT_REGION)
18+
return boto3.client(
19+
service, region_name=settings.AWS_DEFAULT_REGION, config=config
20+
)

commons/enums/BaseResourceEnum.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from enum import Enum
2+
from django.conf import settings
3+
4+
5+
env = settings.ENV
6+
7+
8+
class BaseResourceEnum(Enum):
9+
def __str__(self):
10+
return f"{env}-{self.value}"
11+
12+
@property
13+
def value(self) -> str:
14+
return f"{env}-{super().value}"
15+
16+
@classmethod
17+
def choices(cls):
18+
"""Generate choices for use in Django models."""
19+
return [(item.value, item.name) for item in cls]

file_upload/enum/Buckets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from commons.enums.BaseEnum import BaseEnum
1+
from commons.enums.BaseResourceEnum import BaseResourceEnum
22

33

4-
class BucketType(BaseEnum):
4+
class BucketType(BaseResourceEnum):
55
MENU = "druling-menus"
66
RESTAURANT = "druling-restaurants"
77
DRULING = "druling"

file_upload/services/s3/s3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from botocore.client import Config
23

34
from commons.clients.boto_client import boto_client
45
from setup import settings
@@ -13,7 +14,7 @@ def get_client():
1314
Get an S3 client for AWS or LocalStack.
1415
:return: Configured S3 client.
1516
"""
16-
return boto_client("s3")
17+
return boto_client("s3", config=Config(signature_version="s3v4"))
1718

1819
@staticmethod
1920
def get_endpoint(bucket):

setup/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
SECRET_KEY = os.getenv(
2525
"SECRET_KEY", "django-insecure-@1z*@ng_0yz=i62%mhd#ey+%qib3mwi!ut9ecikxi&t(t=resw"
2626
)
27-
DEBUG = os.getenv("DEV", "False") == "True"
27+
ENV = os.getenv("ENV", "dev")
28+
DEBUG = os.getenv("DEBUG", "False") == "True"
2829
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "*").split(
2930
","
3031
) # Comma-separated values in .env
@@ -218,8 +219,8 @@
218219
CORS_ALLOW_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
219220
else:
220221
CORS_ALLOW_ALL_ORIGINS = False
221-
CORS_ALLOWED_ORIGIN = [
222-
"https://dev.druling.com/",
222+
CORS_ALLOWED_ORIGIN_REGEXES = [
223+
r"^https://.*\.druling\.com$",
223224
]
224225

225226
LOCALSTACK_PORT = os.getenv("LOCALSTACK_PORT", "4566")

user/services/email_verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def send_code(self, data):
2828
"company_name": "Druling",
2929
"verification_code": code,
3030
"user_email": email,
31-
"support_email": "support@yourcompany.com",
31+
"support_email": "support@druling.com",
3232
"expiry_time": "10",
3333
"current_year": datetime.now().year,
3434
}

0 commit comments

Comments
 (0)