pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

HTTP server will not serve images

Open MrSurly opened this issue 5 years ago • 7 comments

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.

  • pdoc version: 0.9.1

MrSurly avatar Oct 09 '20 02:10 MrSurly

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!

kernc avatar Oct 09 '20 02:10 kernc

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.

MrSurly avatar Oct 09 '20 03:10 MrSurly

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).

kernc avatar Oct 09 '20 14:10 kernc

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?

fr34q avatar Oct 12 '20 07:10 fr34q

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?

kernc avatar Oct 12 '20 14:10 kernc

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.

fr34q avatar Oct 12 '20 20:10 fr34q

can i contribute please assign me

tausiq2003 avatar Oct 06 '21 09:10 tausiq2003