arachnys / athenapdf

Drop-in replacement for wkhtmltopdf built on Go, Electron and Docker
MIT License
2.26k stars 186 forks source link

Converting localhost HTML #142

Closed Ethaan closed 6 years ago

Ethaan commented 6 years ago

Hi!

I'm trying to convert an HTML from my localhost.

So for example, I have some files under.

http://localhost:3000/test.html or a dynamic one under http://localhost:3000/invoiceHTML/qTeKYkzB7knm2LQh7

And when I try to convert them like

HTTP.get("http://localhost:4080/convert",{
    npmRequestOptions: { encoding: null },
     params: {
          auth:"arachnys-weaver",
           url: "http://localhost:3000/test.html",
       }
    });

This return.

{
    "error": "PDF conversion failed due to an internal server error"
}

There are 2 things happening here.

1.- Using another website URL apart from localhost make it works (like https://www.washingtonpost.com/world/national-security/whatsapp-the-messaging-service-announces-full-encryption-on-all-platforms/2016/04/05/80f071f6-fb3e-11e5-9140-e61d062438bb_story.html). 2.- If I deploy and make the URL available under the WWW it works.

This is how I'm starting athena (on localhost and deployed version)

docker run -d -p 4080:8080 --name athena --rm arachnysdocker/athenapdf-service

Thanks!

dbuxton commented 6 years ago

Presumably it's because localhost doesn't point to the same place within the docker container?

Ethaan commented 6 years ago

Yeah that make sense, so here what should be more convenient?

1.- forward docker VM to bind into my localhost?

  1. do something (idk what) to point my localhost to docker host?
MrSaints commented 6 years ago

@Ethaan You can expose your host localhost as something like dockerhost. There are some solutions highlighted here (basically, you need to access the internal network IP or map some host to it). You could also share the same network as your host, but I strongly suggest you do not do this.

I'm closing this issue as it is more a constraint of Docker, but feel free to continue the discussion :)

Ethaan commented 6 years ago

@MrSaints thanks for the link.

Following them, I think they give me into the correct direction, but still making calls like.

http://localhost:4080/convert?auth=arachnys-weaver&url=http://localhost:3000/html/157 returns.

{
    "error": "PDF conversion failed due to an internal server error"
}

I might be on the correct road but I think I'm missing something very obvious.

I'm running athena like.

docker run -d -p 4080:8080 --add-host='localhost:192.168.1.73' --name athena --rm arachnysdocker/athenapdf-service

where 192.168.1.73 is the result of running ipconfig getifaddr en0

Other solutions tell me about http://docker.for.mac.localhost:4080/convert so making the requests like

http://docker.for.mac.localhost:4080/convert?auth=arachnys-weaver&url=http://docker.for.mac.localhost:3000/html/157 also return the same error.

Other solution also is adding dockerhost but it seems like as the recent versions docker.for.mac is the best option, but as https://docs.docker.com/docker-for-mac/networking/#httphttps-proxy-support says in this part.

I cannot ping my containers
Docker for Mac is unable to route traffic to containers and from containers back to the host.

i get more confused, do you have an idea about.

how I can make athena docker service connect to the parent localhost have do you ever come across this?, I'm here being a pain in the ass, since this will make my development experience much better, right now i have to deploy to my dev environment, and test the html => pdf conversion and blah blah,

MrSaints commented 6 years ago

@Ethaan Can you check if whatever service underlying http://localhost:3000/test.html is actually allowing hosts outside of localhost ? That is, it should be binding to 0.0.0.0.

You can also try something like:

docker run -d -p 4080:8080 --add-host='localhost:192.168.1.73' --name athena --rm arachnysdocker/athenapdf-service /bin/sh

And try do a cURL to localhost, dockerhost, etc (whatever you used) from there?

Ethaan commented 6 years ago

@MrSaints you right, using --add-host='localhost:192.168.1.73' was working, my issue was that /etc/hosts was using not correctly updated.

Thanks for the help!

Tyga76 commented 6 years ago

@Ethaan I suggest you use host.docker.internal for localhost in the URL on Mac. This way you preserve the localhost of the container.

http://localhost:4080/convert?auth=arachnys-weaver&url=http:// host.docker.internal:3000/html/157

hope this helps