Silicon Valley - Admin commited on
Commit
1d7545f
·
1 Parent(s): 53b7d1b

Update Dockerfile and server.py to enhance static file handling and API routing

Browse files

- Created a structured directory for static files in the Dockerfile.
- Copied Swagger UI and OpenAPI specification files into the static directory.
- Renamed the root endpoint to improve clarity and added a new '/docs' endpoint for redirecting to the Swagger UI.

Files changed (2) hide show
  1. Dockerfile +5 -1
  2. server.py +6 -2
Dockerfile CHANGED
@@ -15,9 +15,13 @@ COPY requirements.txt .
15
  RUN pip install --no-cache-dir --upgrade pip && \
16
  pip install --no-cache-dir -r requirements.txt
17
 
18
- # Crear directorio para archivos estáticos
19
  RUN mkdir -p /code/static
20
 
 
 
 
 
21
  # Copiar el resto de los archivos
22
  COPY . .
23
 
 
15
  RUN pip install --no-cache-dir --upgrade pip && \
16
  pip install --no-cache-dir -r requirements.txt
17
 
18
+ # Crear estructura de directorios
19
  RUN mkdir -p /code/static
20
 
21
+ # Copiar archivos estáticos primero
22
+ COPY static/swagger.html /code/static/
23
+ COPY openapi.yaml /code/
24
+
25
  # Copiar el resto de los archivos
26
  COPY . .
27
 
server.py CHANGED
@@ -8,7 +8,7 @@ import yaml
8
  from pathlib import Path
9
  from typing import Tuple
10
 
11
- from quart import Quart, websocket, request, send_from_directory
12
  from quart_schema import QuartSchema, validate_request, validate_response
13
  from quart_cors import cors
14
  from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
@@ -86,9 +86,13 @@ class ErrorResponse:
86
 
87
  # Rutas API
88
  @app.route('/')
89
- async def swagger_ui():
90
  return await send_from_directory('static', 'swagger.html')
91
 
 
 
 
 
92
  @app.route('/openapi.yaml')
93
  async def openapi():
94
  return openapi_spec
 
8
  from pathlib import Path
9
  from typing import Tuple
10
 
11
+ from quart import Quart, websocket, request, send_from_directory, redirect
12
  from quart_schema import QuartSchema, validate_request, validate_response
13
  from quart_cors import cors
14
  from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
 
86
 
87
  # Rutas API
88
  @app.route('/')
89
+ async def root():
90
  return await send_from_directory('static', 'swagger.html')
91
 
92
+ @app.route('/docs')
93
+ async def docs():
94
+ return redirect('/')
95
+
96
  @app.route('/openapi.yaml')
97
  async def openapi():
98
  return openapi_spec