XciD's picture
XciD HF staff
initial commit
8969f81
raw history blame
No virus
1.92 kB
import * as os from 'os';
const HOSTNAME = os.hostname().split('.')[0];
type EnvironmentType = "development" | "production" | "staging";
export class Environment {
static development: EnvironmentType = "development";
static production: EnvironmentType = "production";
static staging: EnvironmentType = "staging";
static current(): EnvironmentType {
switch (process.env.NODE_ENV) {
case Environment.development:
return Environment.development;
case Environment.production:
return Environment.production;
case Environment.staging:
return Environment.staging;
default:
return ["banana", "katia"].includes(HOSTNAME)
? Environment.production
: Environment.development
}
}
}
export class Configuration {
static prepareProperty<T>(prop: {[index: string]: T}): T {
if (typeof prop === 'object' && Object.keys(prop).includes(Environment.current())) {
return prop[Environment.current()];
}
// Fallback on development config
return prop[Environment.development];
}
}
export const config = {
environment: Environment.current(),
hostname: HOSTNAME, // (katia).huggingface.co || (banana).huggingface.co || ...
appPort: Configuration.prepareProperty<number>({
[Environment.production]: 3210,
[Environment.development]: 3210,
[Environment.staging]: 3210,
}),
transformerAutocompleteUrl: Configuration.prepareProperty<string>({
[Environment.production]: "https://transformer.huggingface.co",
[Environment.development]: "http://localhost:3210",
[Environment.staging]: "https://transformer-staging.huggingface.co",
}),
mongoUrl: process.env.NODE_MONGODB_URL ?? "mongodb://localhost:27017",
mongoDbName: Configuration.prepareProperty<string>({
[Environment.production]: "transformer-autocomplete",
[Environment.development]: "transformer-autocomplete",
[Environment.staging]: "transformer-autocomplete-staging",
}),
}