plutov / formulosity

Self-hosted Surveys as Code platform.
https://formulosity.vercel.app
MIT License
181 stars 20 forks source link

Use NGINX in the container to proxy requests #17

Closed brtwrst closed 2 months ago

brtwrst commented 2 months ago

Hi,

I have based the container on a nonroot NGINX container that listens on port 8081 Requests to / are proxied to the frontend running on 3000 Requests to /api are proxied to the backend on port 8080

Some things are still a bit bodged and can be improved:

  1. Make Node app listen on 127.0.0.1
    when the Node app starts up it prints this for me: formulosity-1 | - Local: http://f9361d85ded3:3000 formulosity-1 | - Network: http://172.21.1.2:3000 It is actually not listening on 127.0.0.1 or localhost, only on the IP of the docker container or the random hostname of the container. I could not figure out how to make it listen on localhost. This leads to some complication with the nginx config file where I have to replace some text after the container starts up. This could all be removed if the Node app would listen on 127.0.0.1. The server.js file includes this line const hostname = process.env.HOSTNAME || '0.0.0.0' but is automatically generated and I don't know how to change it at build time. The API listens on 127.0.0.1

  2. Don't use CONSOLE_API_ADDR=http://127.0.0.1:8081/api: For the combined image with NGINX this is basically always the URL that is typed into the browser + /api so if the app could somehow check if this ENV Variable exists and
    if yes -> use it
    if no -> just add /api to the current base url
    then this variable can be removed from the compose file

  3. Minor: Change the port of the backend API Nginx rootless canonically listens on 8080 but this port is taken up by the backend. If the backend port can be changed (backend port doesn't matter because it is not exposed to the outside) nginx could use the "standard port"

vercel[bot] commented 2 months ago

@brtwrst is attempting to deploy a commit to the formulosity Team on Vercel.

A member of the Team first needs to authorize it.

brtwrst commented 2 months ago

That's fair. We can always include it later and/or include it as an optional way to build the Project with a separate Dockerfile and compose file.