Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Подключил CORS, добавил документацию #12

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
'rest_framework',
'django_extensions',
'django_filters',
'drf_yasg',
'corsheaders',

'custom_user.apps.CustomUserConfig',
'products.apps.ProductsConfig',
Expand Down Expand Up @@ -91,6 +93,7 @@
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -151,6 +154,19 @@
]


# CORS integration
# https://pypi.org/project/django-cors-headers/#description (CSRF Integration)

CORS_ALLOWED_ORIGINS = [
"https://read-only.example.com",
"https://read-and-write.example.com",
]

CSRF_TRUSTED_ORIGINS = [
"https://read-and-write.example.com",
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

Expand Down
21 changes: 21 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@
"""
from django.contrib import admin
from django.urls import path, include
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView


schema_view = get_schema_view(
openapi.Info(
title="Marketplace API template",
default_version='v1',
description="Here you can find all the information about requests and check them",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(url="https://github.com/Abramov0Alexandr"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)


urlpatterns = [
path('admin/', admin.site.urls),
path('users/', include('custom_user.urls', namespace='custom_user')),
Expand All @@ -27,4 +44,8 @@
# authorization urls
path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

# documentation
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ django-filter = "^23.3"
pillow = "^10.0.1"
pyparsing = "^3.1.1"
pydot = "^1.4.2"
django-cors-headers = "^4.2.0"


[build-system]
Expand Down