backend-common: allow port in config to be both a number or a string

This commit is contained in:
Patrik Oldsberg
2020-12-01 10:51:02 +01:00
parent 7aa0830abb
commit 6123682748
3 changed files with 19 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Allow the `backend.listen.port` config to be both a number or a string.
+1 -1
View File
@@ -29,7 +29,7 @@ export interface Config {
/** Address of the interface that the backend should bind to. */
address?: string;
/** Port that the backend should listen to. */
port?: number;
port?: string | number;
};
/** HTTPS configuration for the backend. If omitted the backend will serve HTTP */
@@ -18,7 +18,7 @@ import { Config } from '@backstage/config';
import { CorsOptions } from 'cors';
export type BaseOptions = {
listenPort?: number;
listenPort?: string | number;
listenHost?: string;
};
@@ -89,8 +89,19 @@ export function readBaseOptions(config: Config): BaseOptions {
});
}
const port = config.getOptional('listen.port');
if (
typeof port !== 'undefined' &&
typeof port !== 'number' &&
typeof port !== 'string'
) {
throw new Error(
`Invalid type in config for key 'backend.listen.post', got ${typeof port}, wanted string or number`,
);
}
return removeUnknown({
listenPort: config.getOptionalNumber('listen.port'),
listenPort: port,
listenHost: config.getOptionalString('listen.host'),
baseUrl: config.getOptionalString('baseUrl'),
});