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
working_dir: /app
command: sh /app/docker/start.sh
db:
image: postgres:14-alpine
volumes:
- db:/var/lib/postgresql/data
- ./backups:/docker-entrypoint-initdb.d
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: database
@ -42,4 +43,4 @@ services:
ADMINER_DESIGN: lucas-sandery
volumes:
db:
db:

View File

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

View File

@ -61,7 +61,7 @@ ROOT_URLCONF = 'project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [ BASE_DIR / 'dist/' ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@ -129,7 +129,9 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# 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
# 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_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'DEFAULT_FILTER_BACKENDS': ['rest_framework.filters.OrderingFilter'],
# 'PAGE_SIZE': 15,
}
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [
"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
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.urls import path, include
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 = [
# path('', frontend),
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
path('docs/', include_docs_urls(title = 'API Documentation')),
]
# + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)