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

Enable usage of docker networks by using next.js env variables #878

Open
olafgeibig opened this issue Oct 1, 2024 · 2 comments
Open

Enable usage of docker networks by using next.js env variables #878

olafgeibig opened this issue Oct 1, 2024 · 2 comments

Comments

@olafgeibig
Copy link

olafgeibig commented Oct 1, 2024

Problem
I want to run gpt-researcher on my home server but port 8000 is already taken and moreover I don't like to expose the API to my host network. The compose app could utilize a docker network to avoid that but for that the backend URLs must be configurable. Currently there is no way to set the gpt-researcher backend URLs that are used by the frontend but this is a good practice and there are canonical env variables for this purpose in next.js.

Solution
For my deployment case I can modify the docker-compose file so that the backend is exposed not on the host but on a docker network and my reverse proxy is taking care to forward from the proxy host (researcher.example) to the respective docker network host names: gpt-researcher and gptr-nextjs.
But for this I need that the frontend app is using the canonical env variables (NEXT_PUBLIC_* see next.js docs to construct the URLs for the backend that I set in the compose file like this:

    environment:
      - CHOKIDAR_USEPOLLING=true
      - NEXT_PUBLIC_API_URL=http://researcher.example/api
      - NEXT_PUBLIC_WS_URL=ws://researcher.example/ws

For the default compose file it could simply be http://localhost:8000/api

Alternatives
Nothing I know except exposing port 8000 on the host network which is undesirable.

@ElishaKay
Copy link
Collaborator

ElishaKay commented Oct 2, 2024

Good call @olafgeibig

Agreed.

The final step would be to leverage the NextJS env variable anywhere within frontend/nextjs where localhost:8000 is defined explcitly.

Screen Shot 2024-10-02 at 7 53 08

In other words, these 2-3 cases should leverage the getHost function (which leverages the NextJS env)

Love the idea of putting the NextJS env in the docker-compose :) i.e. If it can work out of the box that is ideal & users should be able to easily see (in 1 place) what services are sitting where & what's pointing where

Would be happy to collab with you to take this to Production.

Feel comfortable to create a PR with your ideas & I can follow up with the above commits.

@olafgeibig
Copy link
Author

Sorry, I had been quite busy. I don't feel qualified to drive the forward or create a PR. I'm not a frontend dev and I don't know NextJS. I just noticed these env variables in other docker-compose files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants