Skip to content
Back

Issues with Environment Variables Changing on Appwrite Server

  • 0
  • Self Hosted
  • Functions
VanillaFish
17 Jan, 2025, 15:02

I am encountering a problem where environment variables are unexpectedly modified at runtime on my Appwrite server (version 1.6.0) hosted at https://custom-domain.tld. Here is the JavaScript configuration I'm using:

TypeScript
const client = new Client()
    .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(process.env.APPWRITE_FUNCTION_API_KEY);

The environment variable for the API endpoint is set as follows:

TypeScript
APPWRITE_FUNCTION_API_ENDPOINT="https://custom-domain.tld/v1"

Despite being correctly configured on the server, APPWRITE_FUNCTION_API_ENDPOINT changes to https:///v1 during runtime.

Using a hardcoded endpoint avoids this issue:

TypeScript
const client = new Client()
    .setEndpoint("https://custom-domain.tld/v1")
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(process.env.APPWRITE_FUNCTION_API_KEY);

Additionally, there was a protocol issue where, despite the endpoint protocol being set to https, it appeared to operate over http internally. I resolved this by enforcing HTTPS in the Appwrite environment settings:

TypeScript
_APP_OPTIONS_FORCE_HTTPS=enabled

I'm sharing this issue to find out if this behavior is intentional or if I might have misconfigured or misunderstood something. Any insights or similar experiences would be greatly appreciated.

Thanks a lot! ❤️

TL;DR
Developers are experiencing unexpected changes in environment variables on their Appwrite server. The issue seems to involve the automatic modification of a specific environment variable at runtime. A potential workaround is to hardcode the affected variable temporarily. Additionally, solving a protocol issue requires enforcing HTTPS in the Appwrite environment settings. Reviewing the setup based on the platform's documentation may be beneficial.
Kenny
17 Jan, 2025, 15:07

are you setting that environment variable inside the appwrite console?

VanillaFish
17 Jan, 2025, 15:09

i am setting it via the functions > settings > Environment variables:

Kenny
17 Jan, 2025, 15:09

I'm wondering if the issue is coming up because that environment variable is kinda like a reserved word and set automatically.

VanillaFish
17 Jan, 2025, 15:10

on local development it is set via the .env file and it is working fine

Kenny
17 Jan, 2025, 15:10

If you change it to something else, does it still get overwritten?

Kenny
17 Jan, 2025, 15:11

That environment variable is one that is set by appwrite at runtime, off the top of my head I don't know exactly how locally run functions work, but on the platform it's set. Could you see if changing it has any effect?

https://appwrite.io/docs/products/functions/develop#environment-variables

VanillaFish
17 Jan, 2025, 15:11

for me it looks like, that there is internally a function that wants to clear some parts like the protocol and if it is like the same host it tries to use just the short local url

VanillaFish
17 Jan, 2025, 15:12

ok, i understand, if this variable is available during runtime, this will not be overwritten by my .env, because it wants to use the internal one

VanillaFish
17 Jan, 2025, 15:14

i will test it tomorrow, if it will change with a different naming of the env variable

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more