Skip to content

Commit

Permalink
fix: coerce port to number in ConnectionOptionsEnvReader
Browse files Browse the repository at this point in the history
the expected type of `port` in all drivers is a number - and
in MSSQL this is a problem as the underlying driver does not
properly handle a string port - so we have to parseInt

closes #6781
  • Loading branch information
imnotjames committed Sep 25, 2020
1 parent b55a417 commit 5098d16
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/connection/options-reader/ConnectionOptionsEnvReader.ts
Expand Up @@ -21,7 +21,7 @@ export class ConnectionOptionsEnvReader {
type: PlatformTools.getEnvVariable("TYPEORM_CONNECTION") || (PlatformTools.getEnvVariable("TYPEORM_URL") ? PlatformTools.getEnvVariable("TYPEORM_URL").split("://")[0] : undefined),
url: PlatformTools.getEnvVariable("TYPEORM_URL"),
host: PlatformTools.getEnvVariable("TYPEORM_HOST"),
port: PlatformTools.getEnvVariable("TYPEORM_PORT"),
port: this.stringToNumber(PlatformTools.getEnvVariable("TYPEORM_PORT")),
username: PlatformTools.getEnvVariable("TYPEORM_USERNAME"),
password: PlatformTools.getEnvVariable("TYPEORM_PASSWORD"),
database: PlatformTools.getEnvVariable("TYPEORM_DATABASE"),
Expand Down Expand Up @@ -95,4 +95,14 @@ export class ConnectionOptionsEnvReader {
return variable.split(",").map(str => str.trim());
}

/**
* Converts a string which contains a number into a javascript number
*/
private stringToNumber(value: any): number|undefined {
if (!value) {
return undefined;
}

return parseInt(value);
}
}

0 comments on commit 5098d16

Please sign in to comment.