Use environment variable inside nx project.json

Viewed 379

I'm using nx as my monorepo management tool, which contains typescript apis and angular frontends.
Now i'm trying to get my project running inside github codespaces.

Everything works fine except the angular applications, when I try to serve them.
The I get and error Invalid Host/Origin header. This issue can be resolved using the --public-host flag.

This is how I can now server my angular applications using the codespaces environment variable CODESPACE_NAME and nx cli:

npx nx serve application --publicHost=${CODESPACE_NAME}-4080.githubpreview.dev:443

My question is now, if it's possible to configure a new target inside project.json to serve my application like npx nx run application:codespaces?

I already tried to create a new target but it does not resolve the environment variable:

...
 "codespaces": {
  "executor": "@angular-devkit/build-angular:dev-server",
  "configurations": {
    "production": {
      "browserTarget": "console:build:production"
    },
    "development": {
      "browserTarget": "console:build:development"
    }
  },
  "defaultConfiguration": "development",
  "options": {
    "publicHost": "${CODESPACE_NAME}-4080.githubpreview.dev:443",
    "port": 4080
  }
},
...
1 Answers

One option is to pre-process the JSON file using the approach described here.

    export FOO=foobar 
    echo {"foo": "$FOO"} > myjson.json 
    envsubst < myjson.json
    output: {foo: foobar}
Related