This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
120 lines (116 loc) · 2.95 KB
/
config.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require("dotenv").config();
const config = {
local: {
urls: ["localhost:3000"],
aws: {
apiGateway: {
name: "api",
region: "local",
endpoint: "http://localhost:3001/local",
},
cognito: {
region: "eu-west-1",
userPoolId: "eu-west-1_56HNtjDYs",
userPoolWebClientId: "6hja5oevagicnu603gjs225e0g",
identityPoolId: "eu-west-1:8cfbc754-898e-48da-9cec-8e91d6dc2b7b",
},
elasticsearch: {
endpoint: "localhost:9200",
region: "local",
},
},
mongo: {
endpoint: "mongodb://127.0.0.1:27017",
db: process.env.MONGODB_DBNAME_DEV,
},
},
dev: {
urls: [
/^mna-admin-dev.netlify.app$/g,
/^deploy-preview-[0-9]+--mna-admin-dev.netlify.app$/g,
/^mna-admin-recette.netlify.app$/g,
/^deploy-preview-[0-9]+--mna-admin-recette.netlify.app$/g,
],
aws: {
apiGateway: {
name: "api",
region: "eu-west-3",
endpoint: "https://r7mayzn08d.execute-api.eu-west-3.amazonaws.com/dev",
},
cognito: {
region: "eu-west-1",
userPoolId: "eu-west-1_56HNtjDYs",
userPoolWebClientId: "6hja5oevagicnu603gjs225e0g",
identityPoolId: "eu-west-1:8cfbc754-898e-48da-9cec-8e91d6dc2b7b",
},
elasticsearch: {
region: "eu-west-3",
endpoint: "search-mna-es-dev-4p4det7qgnd7fp7k77kon32gwi.eu-west-3.es.amazonaws.com",
},
},
mongo: {
endpoint: process.env.MONGODB_URL_DEV,
db: process.env.MONGODB_DBNAME_DEV,
},
},
prod: {
urls: [/^mna-admin-prod.netlify.app$/g],
aws: {
apiGateway: {
name: "api",
region: "eu-west-3",
endpoint: "https://c7a5ujgw35.execute-api.eu-west-3.amazonaws.com/prod",
},
cognito: {
region: "eu-west-1",
userPoolId: "eu-west-1_G2jBocLNF",
userPoolWebClientId: "7f6l402uvs03tnviuk4oqtslqg",
identityPoolId: "eu-west-1:6cca62cd-dfc0-414f-a2cc-c05fe5a01c18",
},
elasticsearch: {
region: "eu-west-3",
endpoint: "search-mna-es-prod-uvteou2uz65vgfcijxw74p4al4.eu-west-3.es.amazonaws.com",
},
},
mongo: {
endpoint: process.env.MONGODB_URL_PROD,
db: process.env.MONGODB_DBNAME_PROD,
},
},
};
const getConfig = envName => {
switch (envName) {
case "prod":
return config.prod;
case "dev":
return config.dev;
case "local":
default:
return config.local;
}
};
let env = null;
const getEnvName = (hostname = "") => {
if (env) {
// Env already setled
return env;
}
if (!hostname) {
// node env
return process.env.STAGE;
}
// Browser env
if (config.dev.urls.some(regexp => regexp.test(hostname))) {
env = "dev";
} else if (config.prod.urls.some(regexp => regexp.test(hostname))) {
env = "prod";
} else {
env = "local";
}
return env;
};
module.exports = {
getEnvName,
getConfig,
config: getConfig(getEnvName()),
};