Separate port and host in configuration

Many cloud providers have an environment variable PORT.
an application is supposed to listen in that port.

Currently,  the yaml for listen address looks like this:
```yaml
backend:
  listen: 0.0.0.0:7000
```

the problem is that I can't use the port environment variable there.

This PR changes it to this:
```yaml
backend:
  listen:
    host: 0.0.0.0
    port: 7000
```

if I want to use the PORT environment variable, now I can do it like this:

```yaml
backend:
  listen:
    host: 0.0.0.0
    port:
      $secret:
         env: PORT
```
This commit is contained in:
Paul Pacheco
2020-08-13 12:27:11 -05:00
parent 65f3f4f95a
commit e9d4ec7494
3 changed files with 17 additions and 6 deletions
@@ -37,11 +37,18 @@ export type BaseOptions = {
* ```
*/
export function readBaseOptions(config: ConfigReader): BaseOptions {
// TODO(freben): Expand this to support more addresses and perhaps optional
const { host, port } = parseListenAddress(config.getString('listen'));
if (typeof config.get('listen') === 'string') {
// TODO(freben): Expand this to support more addresses and perhaps optional
const { host, port } = parseListenAddress(config.getString('listen'));
return removeUnknown({
listenPort: port,
listenHost: host,
});
}
return removeUnknown({
listenPort: port,
listenHost: host,
listenPort: config.getOptionalNumber('listen.port'),
listenHost: config.getOptionalString('listen.host'),
});
}
@@ -7,7 +7,9 @@ organization:
backend:
baseUrl: http://localhost:7000
listen: 0.0.0.0:7000
listen:
host: 0.0.0.0
port: 7000
cors:
origin: http://localhost:3000
methods: [GET, POST, PUT, DELETE]