Skip to content

Commit a1034a7

Browse files
committed
added apis
1 parent b9cb621 commit a1034a7

20 files changed

+507
-394
lines changed

Roadside_backend/asgi.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
# import os
2+
# from django.core.asgi import get_asgi_application
3+
# from channels.routing import ProtocolTypeRouter, URLRouter
4+
5+
6+
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Roadside_backend.settings')
7+
8+
# application = ProtocolTypeRouter({
9+
# "http": get_asgi_application(),
10+
# "websocket":
11+
# URLRouter(
12+
# websocket_urlpatterns
13+
# ),
14+
# })
15+
16+
117
import os
218
from django.core.asgi import get_asgi_application
319
from channels.routing import ProtocolTypeRouter, URLRouter
4-
from channels.auth import AuthMiddlewareStack
5-
from chat_support.routing import websocket_urlpatterns
20+
import importlib
621

722
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Roadside_backend.settings')
823

924
application = ProtocolTypeRouter({
10-
"http": get_asgi_application(),
11-
"websocket": AuthMiddlewareStack(
12-
URLRouter(
13-
websocket_urlpatterns
14-
)
25+
"http": get_asgi_application(),
26+
"websocket": URLRouter(
27+
importlib.import_module('chat_support.routing').websocket_urlpatterns
1528
),
1629
})

Roadside_backend/settings.py

Lines changed: 65 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,33 @@
1-
"""
2-
Django settings for SeeMe_be project.
3-
4-
Generated by 'django-admin startproject' using Django 5.1.1.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/5.1/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/5.1/ref/settings/
11-
"""
12-
131
from pathlib import Path
2+
from decouple import config, Csv
3+
from datetime import timedelta
144

15-
# Build paths inside the project like this: BASE_DIR / 'subdir'.
5+
# Base directory of the project
166
BASE_DIR = Path(__file__).resolve().parent.parent
177

18-
19-
# Quick-start development settings - unsuitable for production
20-
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21-
22-
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'django-insecure-5hex$m9=j7f&ur7xe3qh$t^3_6!#yc)uymrkmii)hz$z^9$yzx'
24-
25-
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
27-
28-
ALLOWED_HOSTS = ["*","127.0.0.1"]
29-
8+
# Environment configurations
9+
SECRET_KEY = config('SECRET_KEY')
10+
DEBUG = config('DEBUG', default=False, cast=bool)
11+
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='', cast=Csv())
3012

3113
# Application definition
32-
3314
INSTALLED_APPS = [
15+
'daphne',
3416
'django.contrib.admin',
3517
'django.contrib.auth',
3618
'django.contrib.contenttypes',
3719
'django.contrib.sessions',
3820
'django.contrib.messages',
3921
'django.contrib.staticfiles',
40-
#installed
22+
# Third-party apps
4123
'rest_framework',
4224
'rest_framework_simplejwt',
4325
'django_filters',
44-
'corsheaders',
26+
'corsheaders',
4527
'django_extensions',
4628
'channels',
47-
#my models
29+
'django_redis',
30+
# Custom apps
4831
'users',
4932
'vendor',
5033
'authentication',
@@ -55,7 +38,7 @@
5538
]
5639

5740
MIDDLEWARE = [
58-
'corsheaders.middleware.CorsMiddleware',
41+
'corsheaders.middleware.CorsMiddleware',
5942
'django.middleware.security.SecurityMiddleware',
6043
'django.contrib.sessions.middleware.SessionMiddleware',
6144
'django.middleware.common.CommonMiddleware',
@@ -65,8 +48,8 @@
6548
'django.middleware.clickjacking.XFrameOptionsMiddleware',
6649
]
6750

68-
6951
CORS_ALLOW_ALL_ORIGINS = True
52+
7053
ROOT_URLCONF = 'Roadside_backend.urls'
7154

7255
TEMPLATES = [
@@ -85,76 +68,64 @@
8568
},
8669
]
8770

88-
# WSGI_APPLICATION = 'Roadside_backend.wsgi.application'
89-
ASGI_APPLICATION = "Roadside_backend.asgi.application"
90-
AUTH_USER_MODEL = "users.User"
91-
92-
# Database
93-
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
71+
ASGI_APPLICATION = 'Roadside_backend.asgi.application'
72+
AUTH_USER_MODEL = 'users.User'
9473

95-
# settings.py
74+
# Database configuration
9675
DATABASES = {
9776
'default': {
9877
'ENGINE': 'django.db.backends.postgresql',
99-
'NAME': 'postgres',
100-
'USER': 'postgres.ikxkxghdwtyyeuyxtdme',
101-
'PASSWORD': 'Vipul@roadside123',
102-
'HOST': 'aws-0-ap-south-1.pooler.supabase.com',
103-
'PORT': '6543',
78+
'NAME': config('DATABASE_NAME'),
79+
'USER': config('DATABASE_USER'),
80+
'PASSWORD': config('DATABASE_PASSWORD'),
81+
'HOST': config('DATABASE_HOST'),
82+
'PORT': config('DATABASE_PORT', cast=int),
10483
}
10584
}
10685

107-
86+
# Channel layers configuration
10887
CHANNEL_LAYERS = {
10988
"default": {
11089
"BACKEND": "channels.layers.InMemoryChannelLayer",
11190
},
11291
}
11392

114-
# Password validation
115-
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
93+
# Redis cache configuration
94+
CACHES = {
95+
"default": {
96+
"BACKEND": "django_redis.cache.RedisCache",
97+
"LOCATION": config('REDIS_LOCATION'),
98+
"OPTIONS": {
99+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
100+
},
101+
}
102+
}
103+
104+
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
105+
SESSION_CACHE_ALIAS = "default"
116106

107+
# Password validation
117108
AUTH_PASSWORD_VALIDATORS = [
118-
{
119-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
120-
},
121-
{
122-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
123-
},
124-
{
125-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
126-
},
127-
{
128-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
129-
},
109+
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
110+
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
111+
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
112+
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
130113
]
131114

132-
133115
# Internationalization
134-
# https://docs.djangoproject.com/en/5.1/topics/i18n/
135-
136116
LANGUAGE_CODE = 'en-us'
137-
138117
TIME_ZONE = 'UTC'
139-
140118
USE_I18N = True
141-
142119
USE_TZ = True
143120

144-
145-
# Static files (CSS, JavaScript, Images)
146-
# https://docs.djangoproject.com/en/5.1/howto/static-files/
147-
121+
# Static files
148122
STATIC_URL = 'static/'
149123

150-
# Default primary key field type
151-
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
152-
153124
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
154125

155-
126+
# Django REST framework settings
156127
REST_FRAMEWORK = {
157-
'DEFAULT_AUTHENTICATION_CLASSES': (
128+
'DEFAULT_AUTHENTICATION_CLASSES': (
158129
'rest_framework_simplejwt.authentication.JWTAuthentication',
159130
),
160131
'DEFAULT_PERMISSION_CLASSES': (
@@ -166,29 +137,34 @@
166137
),
167138
}
168139

169-
from datetime import timedelta
170-
140+
# Simple JWT settings
171141
SIMPLE_JWT = {
172-
'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
142+
'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
173143
'REFRESH_TOKEN_LIFETIME': timedelta(days=40),
174-
'ROTATE_REFRESH_TOKENS': True,
175-
'BLACKLIST_AFTER_ROTATION': True,
176-
177-
'ALGORITHM': 'HS256',
178-
'SIGNING_KEY': SECRET_KEY,
179-
'VERIFYING_KEY': None,
180-
181-
'AUTH_HEADER_TYPES': ('Bearer',),
144+
'ROTATE_REFRESH_TOKENS': True,
145+
'BLACKLIST_AFTER_ROTATION': True,
146+
'ALGORITHM': 'HS256',
147+
'SIGNING_KEY': SECRET_KEY,
148+
'AUTH_HEADER_TYPES': ('Bearer',),
182149
'USER_ID_FIELD': 'id',
183150
'USER_ID_CLAIM': 'user_id',
184-
185151
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
186152
'TOKEN_TYPE_CLAIM': 'token_type',
187-
188153
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
189-
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
154+
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
190155
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
191156
}
192157

193-
194-
158+
# App environment configuration
159+
APP_ENV = config('APP_ENV', default='dev')
160+
161+
if APP_ENV == 'prod':
162+
DEBUG = False
163+
# Production-specific configurations
164+
STATIC_ROOT = BASE_DIR / 'staticfiles'
165+
SECURE_SSL_REDIRECT = True
166+
SESSION_COOKIE_SECURE = True
167+
CSRF_COOKIE_SECURE = True
168+
SECURE_HSTS_SECONDS = 3600
169+
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
170+
SECURE_HSTS_PRELOAD = True

a.drawio

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)