pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.13k stars 146 forks source link

HTTP server will not serve images #267

Open MrSurly opened 4 years ago

MrSurly commented 4 years ago

Expected Behavior

Images are served by http server

Actual Behavior

Images return a 302 and a URL that ultimately results in a 404.

Steps to Reproduce

  1. Generate documentation that has images
  2. Run the http server

Additional info

Starting pdoc server on localhost:8080
pdoc server ready at http://localhost:8080
127.0.0.1 - - [08/Oct/2020 19:05:00] "GET /modelgen.modelgen/ HTTP/1.1" 200 -
127.0.0.1 - - [08/Oct/2020 19:05:00] "GET /modelgen.modelgen/img/screw_hole.svg HTTP/1.1" 302 -
127.0.0.1 - - [08/Oct/2020 19:05:00] "GET /modelgen.modelgen/img/screw_hole.svg/ HTTP/1.1" 404 -

Note that accessing the files directly via file:// works as expected.

kernc commented 4 years ago

Thanks! The culprit seems to be these lines: https://github.com/pdoc3/pdoc/blob/d8b9dbc2a128099e89a9d7859720dac56d574094/pdoc/cli.py#L225-L228 Let me think about it. :thinking: PR welcome!

MrSurly commented 4 years ago

I gave it a shot (a PR), but it seems to render on-the-fly rather than rendering to a directory, so it didn't really work out.

kernc commented 4 years ago

Well yeah, it's a HTTP server: :smiley: https://github.com/pdoc3/pdoc/blob/d8b9dbc2a128099e89a9d7859720dac56d574094/pdoc/cli.py#L155

I'd say the branch condition above needs to be modified to account for other files that are not module documents and maybe default to SimpleHTTPRequestHandler.do_GET() behavior for those files (if _WebDoc inherits from SimpleHTTPRequestHandler instead, maybe simply super().do_GET() can be called).

fr34q commented 4 years ago

I am also facing this issue ( https://github.com/pdoc3/pdoc/issues/268 ).

Not 100% sure if it makes a difference for the solution but the issue is also there when generating the documentation with pdoc3 --html. The browser also does not find the image, and this should all be static content I believe?

kernc commented 4 years ago

Since with --html pdoc just converts markdown ![alt](image) to HTML <img src="image" alt="alt">, I believe it's a question of relative path addressing. Where is the image located relative to the document? Have you tried to address it relative to the project root or the CWD?

fr34q commented 4 years ago

I guess the problem is that the images are not copied at all into the output directory. I used relative adressing, e.g. test.svg when the image is located in the same folder as the python file. In https://github.com/pdoc3/pdoc/issues/268 I also described a minimal example to reproduce it.

tausiq2003 commented 3 years ago

can i contribute please assign me