commit 27/06/2023

develop/Rodrigo/Backend
Francisco Sandoval 2023-06-27 20:09:28 -04:00
parent afcd290000
commit 4abf741738
4 changed files with 39 additions and 12 deletions

View File

@ -21,11 +21,12 @@ services:
- ../:/app - ../:/app
working_dir: /app working_dir: /app
command: sh /app/docker/start.sh command: sh /app/docker/start.sh
db: db:
image: postgres:14-alpine image: postgres:14-alpine
volumes: volumes:
- db:/var/lib/postgresql/data - db:/var/lib/postgresql/data
- ./backups:/docker-entrypoint-initdb.d
environment: environment:
POSTGRES_PASSWORD: password POSTGRES_PASSWORD: password
POSTGRES_DB: database POSTGRES_DB: database
@ -42,4 +43,4 @@ services:
ADMINER_DESIGN: lucas-sandery ADMINER_DESIGN: lucas-sandery
volumes: volumes:
db: db:

View File

@ -10,19 +10,29 @@ class ApiMiddleware:
self.get_response = get_response self.get_response = get_response
def __call__(self, request): def __call__(self, request):
# se omite esta regla en documentacion # se omite esta regla en frontend
if not request.headers.get('Authorization') and request.path[0:6] == '/docs/': if request.path == '/' or request.path[0:8] == '/assets/':
response = self.get_response(request) response = self.get_response(request)
return response return response
# se omite esta regla en admin de django
if request.path[0:7] == '/admin/':
response = self.get_response(request)
return response
# se omite esta regla en documentacion
if request.path[0:6] == '/docs/':
response = self.get_response(request)
return response
# se omite esta regla en login # se omite esta regla en login
if request.path == '/api/auth/' and request.method == 'POST': if request.path == '/api/auth/' and request.method == 'POST':
response = self.get_response(request) response = self.get_response(request)
return response return response
if not request.headers.get('Authorization'): if not request.headers.get('Authorization'):
return HttpResponse('Debe indicar el token de autorización', status = 400) return HttpResponse('Debe indicar el token de autorización', status = 400)
authorization = request.headers.get('Authorization').split(' ') authorization = request.headers.get('Authorization').split(' ')
token = authorization[1] token = authorization[1]
@ -47,4 +57,4 @@ class ApiMiddleware:
} }
response = self.get_response(request) response = self.get_response(request)
return response return response

View File

@ -61,7 +61,7 @@ ROOT_URLCONF = 'project.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [ BASE_DIR / 'dist/' ],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -129,7 +129,9 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/ # https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'assets/'
# STATIC_ROOT = '/app/project/dist/assets'
# MEDIA_URL = 'assets/'
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
@ -140,9 +142,9 @@ REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema', 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'DEFAULT_FILTER_BACKENDS': ['rest_framework.filters.OrderingFilter'], 'DEFAULT_FILTER_BACKENDS': ['rest_framework.filters.OrderingFilter'],
# 'PAGE_SIZE': 15,
} }
CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [ CORS_ORIGIN_WHITELIST = [
"http://localhost:3000", "http://localhost:3000",
] "http://transporte.hz.kursor.cl",
]

View File

@ -14,12 +14,26 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from rest_framework.documentation import include_docs_urls from rest_framework.documentation import include_docs_urls
from django.template.loader import get_template
from django.http import HttpResponse
def frontend(request):
plantilla = get_template('index.html')
documento = plantilla.render()
return HttpResponse(documento)
urlpatterns = [ urlpatterns = [
# path('', frontend),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/', include('api.urls')), path('api/', include('api.urls')),
path('docs/', include_docs_urls(title = 'API Documentation')), path('docs/', include_docs_urls(title = 'API Documentation')),
] ]
# + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)