Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not serving .js and .css files? #609

Open
BartStolarek opened this issue Feb 1, 2024 · 1 comment
Open

Not serving .js and .css files? #609

BartStolarek opened this issue Feb 1, 2024 · 1 comment

Comments

@BartStolarek
Copy link

BartStolarek commented Feb 1, 2024

Hi!

I have created a template flask server for myself Template Git Repo.

When I run the server, and try to access the endpoint /apidocs, the static files aren't being loaded. I managed to get around this for the favicon.ico, by adding following code to my init.py:

@server.route('/favicon.ico') def favicon(): return server.send_static_file('favicon.ico')

But it is still not serving the .js and .css files for swagger ui.

I've tried accessing these endpoints via my browser:
/apispec_1.json
/flasgger_static/swagger-ui.css
/flasgger_static/swagger-ui-bundle.js,
/flasgger_static/swagger-ui-standalone-preset.js, and
/flasgger_static/lib/jquery.min.js

And they do load into my browser (i can see them).

I checked network details in my browser, and there is no .js or .css files being loaded.

I'm not getting any server log errors, and not getting any errors in my web browsers console.

If i've missed anything more helpful info, let me know.

I'm just running flask server so no reverse proxy at the moment (if anyone has similar issue and is running a reverse proxy, here is the info for that: Reverse Proxy Info.

I've also tried to externally load swaggerui with this: Externally load swagger UI. This didn't load anything either.

I did find a similar issue 426

Thank you in advance!

@BartStolarek
Copy link
Author

Fixed it:

Turns out in my middleware/response_manipulator.py file my response_manipulator function was the issue.

The response_manipulator function is designed to modify Flask responses before they are sent to the client. Specifically, it adds metadata, sets the Content-Type header to application/json, and adds a custom header. However, this function made an assumption that every response should be JSON, which might not be suitable for all responses, especially for those serving HTML content like the Swagger UI.

Woops!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant