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

HTTP server will not serve images #267

Open
MrSurly opened this issue Oct 9, 2020 · 7 comments
Open

HTTP server will not serve images #267

MrSurly opened this issue Oct 9, 2020 · 7 comments
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest https://hacktoberfest.digitalocean.com

Comments

@MrSurly
Copy link

MrSurly commented Oct 9, 2020

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
@kernc
Copy link
Member

kernc commented Oct 9, 2020

Thanks! The culprit seems to be these lines:

pdoc/pdoc/cli.py

Lines 225 to 228 in d8b9dbc

# Redirect '/pdoc' to '/pdoc/' so that relative links work
# (results in '/pdoc/cli.html' instead of 'cli.html')
elif not self.path.endswith(('/', '.html')):
return self.redirect(self.path + '/')

Let me think about it. 🤔 PR welcome!

@kernc kernc added bug Something isn't working good first issue Good for newcomers Hacktoberfest https://hacktoberfest.digitalocean.com labels Oct 9, 2020
@MrSurly
Copy link
Author

MrSurly commented Oct 9, 2020

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
Copy link
Member

kernc commented Oct 9, 2020

Well yeah, it's a HTTP server: 😃

class _WebDoc(BaseHTTPRequestHandler):

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
Copy link

fr34q commented Oct 12, 2020

I am also facing this issue ( #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
Copy link
Member

kernc commented Oct 12, 2020

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
Copy link

fr34q commented Oct 12, 2020

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 #268 I also described a minimal example to reproduce it.

@tausiq2003
Copy link

can i contribute please assign me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest https://hacktoberfest.digitalocean.com
Development

Successfully merging a pull request may close this issue.

4 participants