-
Notifications
You must be signed in to change notification settings - Fork 0
/
env-config.js
53 lines (47 loc) · 1.42 KB
/
env-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
const {
ISSUER_BASE_URL,
API_URL,
CLIENT_ID,
CLIENT_SECRET,
SESSION_SECRET = "e6de1374433dde92a5bae567b56b01de32ad0d4f0115b7675f5b985720210f4c",
VERCEL_URL,
VERCEL_GITHUB_REPO,
VERCEL_GITHUB_ORG,
PORT = 7000,
} = process.env;
const appUrl = VERCEL_URL
? `https://${VERCEL_GITHUB_REPO}.${VERCEL_GITHUB_ORG.toLowerCase()}.vercel.app`
: `http://localhost:${PORT}`;
function checkUrl() {
return (req, res, next) => {
const host = req.headers.host;
if (!appUrl.includes(host)) {
return res.status(301).redirect(appUrl);
}
return next();
};
}
function removeTrailingSlashFromUrl(url) {
if (!url || !url.endsWith("/")) return url;
return url.substring(0, url.length - 1);
}
console.log("\n----------------------------------");
console.log("Envronment Settings:");
console.log(`ISSUER_BASE_URL: ${ISSUER_BASE_URL}`);
console.log(`API_URL: ${API_URL}`);
console.log(`CLIENT_ID: ${CLIENT_ID}`);
if (CLIENT_SECRET) console.log(`CLIENT_SECRET: Has Value`);
else console.log(`CLIENT_SECRET: Not Set`);
console.log(`APP_URL: ${appUrl}`);
console.log(`SESSION_SECRET: ${SESSION_SECRET}`);
console.log("----------------------------------\n");
module.exports = {
checkUrl,
APP_URL: appUrl,
API_URL: removeTrailingSlashFromUrl(API_URL),
ISSUER_BASE_URL: removeTrailingSlashFromUrl(ISSUER_BASE_URL),
CLIENT_ID: CLIENT_ID,
CLIENT_SECRET: CLIENT_SECRET,
SESSION_SECRET: SESSION_SECRET,
PORT: PORT,
};