Angular static site Apps Platform environment variables

Posted December 8, 2021 185 views
AngularDigitalOcean App Platform

On Digital Ocean’s cool Apps platform, I’ve deployed an angular site as a static site and it is deployed after a push to my repo.

I’d like to make calls to an API and so require an API key and secret.

I’ve set environment files in the angular environment.ts files and used the App Platform / {app} / Settings / App-Level Environment Variables to override the environment so I don’t have to commit the secret to my repo.

But it hasn’t worked. The environment key has a scope of RUNANDBUILD_TIME

Any clues on how I can get it to override?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hey there!

In App Platform static sites are served by a CDN and don’t have access to the runtime environment variables. They only have access to build time env variables unfortunately. One workaround to accomplish this is by using a configuration file and a script. An example of how to do this can be found in the answer here.

Hope it helps!