mjstewart / fakesmtp-web

Web support for FakeSMTP running in docker using Spring Boot
14 stars 10 forks source link

Network error, the server could be down or you are not permitted to access this resource. #1

Closed saybertevgeny closed 5 years ago

saybertevgeny commented 5 years ago

Why? My compose

fakedsmtp:
    image: munkyboy/fakesmtp
    container_name: fake-smtp
    ports: 
      - 25:25
    volumes:
      - ./fake-smtp-emails:/var/mail
    networks:
      - backend
      - frontend

  fakesmtpweb:
    image: mjstewart/fakesmtp-web:1.0
    container_name: fake-smtp-web
    ports: 
      - 60500:8080
    volumes:
      - ./fake-smtp-emails:/var/mail
    environment:
      - EMAIL_INPUT_DIR_POLL_RATE_SECONDS=10
    depends_on:
      - fakedsmtp
    networks:
      - backend
      - frontend
mjstewart commented 5 years ago

It's most likely due to not having correct permissions to access the volume. Could you please try changing the directory permissions. Eg:

chmod +x ./fake-smtp-emails

I recommend using the docker-compose file provided in the repository https://github.com/mjstewart/fakesmtp-web/blob/master/docker-compose.yml. Port numbers should be wrapped in quotes too otherwise it may cause problems.

mam-ijinus commented 5 years ago

hi,

I have the same issue, I've done a chmod 777 on fake-smtp-emails folder and the server stay disconnected.

some file are write into the folder so fake-smtp can write into it.

thanks for help.

mam-ijinus commented 5 years ago

ah!

the request that failed is http://localhost:60500/api/emails?sort=sentDate,desc

but as fake-smtp and fake-smtp-web are not in the same container the localhost is not the same ??

saybertevgeny commented 5 years ago

Hi! I have 777 permission.

yes, i runed into virtual machine, not localhost

mam-ijinus commented 5 years ago

if when you access to the web interface with other things that http://localhost:60500 then you need to rebuild the image or connect trought ssh tunnel.

https://github.com/mjstewart/fakesmtp-web#build-custom-docker-image

mjstewart commented 5 years ago

Did building a new image with different port work? Like you mentioned, this project works on the assumption 60500 is dedicated to fakesmtp-web only.

https://github.com/mjstewart/fakesmtp-web#without-docker-compose shows how to run in 2 different containers without docker-compose. The only requirement is access to a directory on the local machine for both containers to write/read emails to/from. Providing the port is accessible and this directory has correct privileges it should just work. By privileges I also mean chmod and chown to non root user.

Another thing to be careful of is if you are running docker in a VM eg on a mac/windows, its not actually localhost. Its the docker ip address I believe.

mam-ijinus commented 5 years ago

It is possible to set FAKE_SMTP_WEB_API variable in docker compose instead of rebuild an image ?

I don't have yarn install in the machine where I have installed fakesmtp. Having an web interface is great to be used for remote machine but if you need to recompile the image it a little sad. I use a ssh tunnel to have a remote access to the web interface, but for no technical guy who want to test it's a little complex.

mam-ijinus commented 5 years ago

Great job by the way 👍

mjstewart commented 5 years ago

The reason why FAKE_SMTP_WEB_API cannot be set in the docker compose as an alternative to rebuilding the image is because the ui is written as a SPA (single page application).

The REST API runs within the container on port 8080 which is mapped to port 60500 on the host as I assumed this wouldn't clash with anything. It serves up the javascript bundle to the client (your local web browser outside of the container) which then needs to know the details of the docker IP and port mappings.

The heart of the issue is purely being a SPA. When webpack builds the bundle, it needs to embed the endpoint of the docker IP and exposed host port into the javascript code which is done once at build time, not dynamically through environment variables for each API call. If it was a server side application using a templating language then what you are referring to would work out of the box since it would all run on the server within the container.

If you know a way to solve this id love to hear but I believe not much can be done about it except rebuild the image to a suitable ip/port as achieved through updating FAKE_SMTP_WEB_API in ./build.sh. The only hacky solution I can think of is search and replace endpoints in the emitted js bundle based on a docker environment variable which seems like a very bad idea.

I will update the docs to mention this.

mam-ijinus commented 5 years ago

ok, I understand the issue.

I'me just asking myself if it was possible to get the url from the adresse bar (for example: here) and use it for REST request ?

it's no necessary a good idea...

BTW I've rebuild the image and it's works great ! thanks !