se agrega frontend en ruta raiz

develop/Rodrigo/Backend
Francisco Sandoval 2023-07-02 20:12:05 -04:00
parent 4abf741738
commit eaf9124b4e
16 changed files with 143 additions and 31 deletions

View File

@ -10,18 +10,8 @@ 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 frontend # se omite esta regla si no es api
if request.path == '/' or request.path[0:8] == '/assets/': if request.path[0:5] != '/api/':
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) response = self.get_response(request)
return response return response

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
project/dist/avatars/avatar1.jpg vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
project/dist/avatars/avatar2.png vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
project/dist/avatars/avatar3.png vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
project/dist/avatars/avatar4.png vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
project/dist/avatars/avatar5.png vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
project/dist/avatars/avatar6.png vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
project/dist/avatars/avatar7.jpg vendored 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

15
project/dist/index.html vendored 100644
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gestión de Transporte</title>
<script type="module" crossorigin src="/assets/index-fb7fa786.js"></script>
<link rel="stylesheet" href="/assets/index-9c8ce59f.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@ -41,7 +41,7 @@ INSTALLED_APPS = [
'rest_framework', 'rest_framework',
'coreapi', 'coreapi',
'corsheaders', 'corsheaders',
'api' 'api',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -61,7 +61,7 @@ ROOT_URLCONF = 'project.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ BASE_DIR / 'dist/' ], 'DIRS': [ BASE_DIR / 'dist' ],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -129,9 +129,7 @@ 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 = 'assets/' STATIC_URL = 'static/'
# 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
@ -147,4 +145,5 @@ CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [ CORS_ORIGIN_WHITELIST = [
"http://localhost:3000", "http://localhost:3000",
"http://transporte.hz.kursor.cl", "http://transporte.hz.kursor.cl",
"http://transporte-backend.hz.kursor.cl",
] ]

View File

@ -14,26 +14,23 @@ 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.conf import settings
from django.template.loader import get_template from django.conf.urls.static import static
from django.http import HttpResponse from .views import frontend
def frontend(request):
plantilla = get_template('index.html')
documento = plantilla.render()
return HttpResponse(documento)
urlpatterns = [ urlpatterns = [
# path('', frontend), # FRONTEND
path('admin/', admin.site.urls), path('', frontend, name='home'),
# BACKEND
path('api/', include('api.urls')), path('api/', include('api.urls')),
path('admin/', admin.site.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)
urlpatterns += static('assets/', document_root=f'{settings.BASE_DIR}/dist/assets')
urlpatterns += static('avatars/', document_root=f'{settings.BASE_DIR}/dist/avatars')

View File

@ -0,0 +1,7 @@
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)