#Env|Configuration variables array|map values

4 messages · Page 1 of 1 (latest)

stone shuttle
#

Is it possible to have something like:

const currentSeason = 2022
const mappings = new Map([['europe', 'eu'], ['pacific', 'jp']])

to be put in an application wide env/configuration properties?

For the first I could create a .env with e.g.:

PUBLIC_CURRENT_SEASON=2022

but can I do something similar for the mapping?

as in (multiple other places in my code I would like to do something like:

const alpha2Code = mapping.get(name)

PS:
I've used other (non node) server frameworks where this is quite easy to do with e.g. YAML configuration like:

MAPPINGS:
  - europe: eu
  - pacific: jp

wonder how this can be done best with Astro.

cedar sandal
#

.env variables are strings so if you want an array you have to use the “one|two|three”.split(“|”) method to turn your string into an array, it would be easier to do this with a config file instead of .env var

olive arrow
#

The data seems not "secret". You may hardcode the data and export it from a file like app-data.js and import the app-data in your page component.

stone shuttle
#

thx @olive arrow yes I think that's the easiest way to do it.