clinical-biomarkers / biomarker-datasetviewer

Biomarker Backend Dataset Viewer
https://hivelab.biochemistry.gwu.edu/biomarker-partnership/data
0 stars 0 forks source link

API Swagger Page Not Working #1

Closed seankim658 closed 7 hours ago

seankim658 commented 7 months ago

When I try to load swagger page at https://hivelab.tst.biochemistry.gwu.edu/biomarker-partnership/api I get a blank white page. The devtools network tab is as follows: image

I believe the issue is that flask expects the swaggerui static files from the server root. As shown in the "Request initiator chain" the files are being requested from "https://hivelab.tst.biochemistry.gwu.edu/swaggerui/..." instead of "https://hivelab.tst.biochemistry.gwu.edu/biomarker-partnership/api/swaggerui/...".

If I try to visit the direct url where the static files should be served from I can see them. For example, if I visit "https://hivelab.tst.biochemistry.gwu.edu/biomarker-partnership/api/swaggerui/droid-sans.css" directly in my browser I can see the file: image

To attempt to understand the discrepancy of where the static files are being served from I added the following logging to the glyds module __init__.py:

app.logger.debug(f'STATIC FOLDER: {app.static_folder}') app.logger.debug(f'STATIC URL PATH: {app.static_url_path}') app.logger.debug(f'APIDOC STATIC URL PATH: {apidoc._static_url_path}') app.logger.debug(f'APIDOC STATIC FOLDER: {apidoc.static_folder}')

The output is:

DEBUG:glyds:STATIC FOLDER: /app/glyds/static DEBUG:glyds:STATIC URL PATH: /static DEBUG:glyds:APIDOC STATIC URL PATH: /swaggerui DEBUG:glyds:APIDOC STATIC FOLDER: /usr/local/lib/python3.6/site-packages/flask_restx/static

When I exec into the docker api container I can see the static files are in the /usr/local/lib/python3.6/site-packages/flask_restx/static folder (automated from flask_restx). I believe the issue is with where flask is attempting to serve the files from but I'm not 100% sure.

rykahsay commented 7 months ago

From within the container, you may need to edit the html files under template (files shown below).

ls -ltr /usr/local/lib/python3.6/site-packages/flask_restx/templates/

-rw-r--r--. 1 root staff  478 Jul 21 18:54 swagger-ui-libs.html
-rw-r--r--. 1 root staff  950 Jul 21 18:54 swagger-ui-css.html
-rw-r--r--. 1 root staff 4286 Jul 21 18:54 swagger-ui.html

For example, I see "swagger-ui.css" referenced in the file /usr/local/lib/python3.6/site-packages/flask_restx/templates/swagger-ui-css.html

<link media="screen" rel="stylesheet" type="text/css" href="{{ swagger_static('swagger-ui.css') }}" />

Try to edit such lines.