diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index cd8c7c8..ff8b211 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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: \ No newline at end of file + db: diff --git a/project/api/middlewares.py b/project/api/middlewares.py index 1e10b29..72ddabd 100644 --- a/project/api/middlewares.py +++ b/project/api/middlewares.py @@ -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 \ No newline at end of file + return response diff --git a/project/project/settings.py b/project/project/settings.py index 5ac0add..56301f5 100644 --- a/project/project/settings.py +++ b/project/project/settings.py @@ -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", -] \ No newline at end of file + "http://transporte.hz.kursor.cl", +] diff --git a/project/project/urls.py b/project/project/urls.py index 0d6271e..376b6f2 100644 --- a/project/project/urls.py +++ b/project/project/urls.py @@ -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)