File size: 1,922 Bytes
8969f81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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",
	}),
}