Merge pull request #3507 from backstage/rugvip/port

backend-common: allow port in config to be both a number or a string
This commit is contained in:
Patrik Oldsberg
2020-12-01 14:58:55 +01:00
committed by GitHub
4 changed files with 23 additions and 4 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 */
@@ -85,7 +85,10 @@ export class ServiceBuilderImpl implements ServiceBuilder {
const baseOptions = readBaseOptions(backendConfig);
if (baseOptions.listenPort) {
this.port = baseOptions.listenPort;
this.port =
typeof baseOptions.listenPort === 'string'
? parseInt(baseOptions.listenPort, 10)
: baseOptions.listenPort;
}
if (baseOptions.listenHost) {
this.host = baseOptions.listenHost;
@@ -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'),
});