rallly icon indicating copy to clipboard operation
rallly copied to clipboard

Use runtime environment values on client

Open lukevella opened this issue 1 year ago • 12 comments

When we build the docker image for Rallly, values like NEXT_PUBLIC_BASE_URL are set during build time for client side code and do not match what is expected during runtime. We can use next-runtime-env to get the runtime value of these environment variables.

lukevella avatar Sep 12 '23 15:09 lukevella

Came here to report that the app kept redirecting to localhost:3000 and this is probably the reason then. The Cloudron package is built without a final domain, as it is not known yet. Guess we have to wait for a package update then for this to be added.

nebulade avatar Oct 30 '23 18:10 nebulade

@nebulade, is this a new issue in 3.2.0?

lukevella avatar Oct 30 '23 18:10 lukevella

hm I see this issue is much older. Well it was detected by our tests, so I started investigation. Maybe then it is related to https://github.com/lukevella/rallly/commit/703d551aac7647b46039a05fd06662bec0d758a9 ?

nebulade avatar Oct 30 '23 18:10 nebulade

I don't think it's likely to be that. Do you know what the last working version was?

lukevella avatar Oct 30 '23 18:10 lukevella

Last working version was 3.1.0 so possibly then I am chasing the wrong thing. I see that the process.env. usage was always like that so always during the build?

nebulade avatar Oct 30 '23 18:10 nebulade

Maybe should split this into a new issue then. Also we had to apply the same fix exporting HOSTNAME as we had to for https://github.com/baptisteArno/typebot.io/issues/911#issuecomment-1761210931 possibly then some nextjs update making the difference

nebulade avatar Oct 30 '23 18:10 nebulade

I suspect there is some way to fix this but I'd need some steps to be able to reproduce it. Are you able to provide that?

lukevella avatar Oct 30 '23 19:10 lukevella

Tried to get the app working locally to reproduce the issue, but didn't succeed to get it working at all there. So I went to bisect it via a Cloudron build package. For reference its build like this: https://git.cloudron.io/cloudron/rallly-app/-/blob/main/Dockerfile?ref_type=heads The env variables we set during runtime (so after the build) are https://git.cloudron.io/cloudron/rallly-app/-/blob/main/start.sh?ref_type=heads#L26 and that worked before.

So the commit causing the issue after bisecting is 6fa66da6818ef7a41b6f7ff9fdebff36312934e4 which causes a redirect to http://localhost:3000 after initial loading. Will see if I can drill down further to this issue, but any help is much appreciated.

nebulade avatar Oct 31 '23 12:10 nebulade

Ah right that makes sense. You will need to set NEXTAUTH_URL as well to the same value as NEXT_PUBLIC_BASE_URL. Annoyingly this env var is required by next-auth. I didn't want to expose this since it is an implementation detail so it is handled in the start script here: https://github.com/lukevella/rallly/blob/main/scripts/docker-start.sh#L4

lukevella avatar Oct 31 '23 13:10 lukevella

I'll try to change how this is handled so that it doesn't require you to add NEXTAUTH_URL as well though but for now that could be a quick fix.

lukevella avatar Oct 31 '23 13:10 lukevella

Ah right, should have seen that start script change earlier. Have triggered a new test run with it now, so if that works its fine, no need to change this in the code then.

nebulade avatar Oct 31 '23 13:10 nebulade

I can confirm it works with NEXTAUTH_URL also set now. Thanks a lot for your help and sorry for highjacking this, now unrelated issue :/

nebulade avatar Oct 31 '23 13:10 nebulade