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

Passing variables to static files in different stages? #56

Open
chusc123 opened this issue Jul 17, 2020 · 3 comments
Open

Passing variables to static files in different stages? #56

chusc123 opened this issue Jul 17, 2020 · 3 comments

Comments

@chusc123
Copy link

What's the best way to change api key or api domain uri based on a different stage in a single page application?

If this were a lambda, I would use environment variables in the serverless yml file, but since these are static files I'm not sure the best way to do this.

@eahefnawy
Copy link
Member

Not sure of your framework, but you could still use environment variables with React for example:
https://serverless-stack.com/chapters/environments-in-create-react-app.html

Unless I misunderstood your issue? 🤔

@darbio
Copy link

darbio commented Feb 20, 2021

I think the question is:

When I have multiple stages (dev, prod) how do I define different values to my environment variables (e.g. REACT_APP_API_URL) for each stage, using the same serverless.yml.

The current answer is to use .env files, as per #44 .

@dhesson
Copy link

dhesson commented Feb 25, 2021

@eahefnawy Is there no way to set env vars in the serverless.yml and point them to a param from the cloud app settings? I've done this in other apps and it would be disappointing if this isn't possible:

inputs:
  env:
    AUTH_CLIENT_ID: ${param:AUTH_CLIENT_ID}
    AUTH_DOMAIN: ${param:AUTH_DOMAIN}
    AUTH_REDIRECT_URL: ${param:AUTH_REDIRECT_URL}
  src:
    src: ./src
    hook: npm run build
    dist: ./dist

My use case is the redirect URIs are different from prod and dev and this needs injected into the code at build time depending on the stage. None of these are sensitive values so it's fine that they are on the client.

If this is possible, maybe I'm trying to reference them incorrectly. Right now, I just get empty strings or undefined in the React render template.

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

4 participants