HL7v2/packages/server/config.ts

25 lines
827 B
TypeScript

// define available configurations
interface Config {
port: number;
prefixes: string[];
poolSize: number;
}
// construct config object from environment variables
export const config: Config = {
port: parseInt(process.env.PORT || '8080', 10),
prefixes: (process.env.PREFIXES || 'STA').split(","),
poolSize: parseInt(process.env.POOL_SIZE || '100', 10),
};
// validate config
if (isNaN(config.port) || config.port < 1024 || config.port > 49151) {
throw new Error('Invalid PORT environment variable (1024 - 49151)');
}
if (config.prefixes.length === 0) {
throw new Error('Invalid PREFIXES environment variable (length > 1)');
}
if (isNaN(config.poolSize) || config.poolSize < config.prefixes.length) {
throw new Error('Invalid pool size environment variable (poolSize >= prefix.length)');
}