flasgger / flasgger

Easy OpenAPI specs and Swagger UI for your Flask API

Home Page:http://flasgger.pythonanywhere.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not serving .js and .css files?

BartStolarek opened this issue · comments

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!

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!