This repository has been archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
80 lines (66 loc) · 2.07 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
require("dotenv").config();
const path = require("path");
const appConfig = require("./config/configLoader");
const forceDev = false;
module.exports = {};
module.exports.db = {
url: tryNew(URL, process.env.MYSQL_URL) || new URL(appConfig.sql.url)
};
module.exports.session = {
secret: appConfig.session.secret,
cookieName: appConfig.session.cookieName,
};
module.exports.env = {
node: process.env.NODE_ENV || "production",
isDev: forceDev
};
module.exports.env.isDev = module.exports.env.node.startsWith("dev") || forceDev;
// BUG: Make this more strict!
module.exports.helmet = {
contentSecurityPolicy: {
useDefaults: true,
directives: {
defaultSrc: ["'self'", "http:"],
connectSrc: ["'self'", "https:", "ws:"],
scriptSrc: [
"'self'",
"cdnjs.cloudflare.com",
"kit.fontawesome.com",
(req, res) => `'nonce-${res.locals.nonce}'`,
],
workerSrc: ["'self'", "blob:"],
upgradeInsecureRequests: null
}
}
};
if(module.exports.env.isDev) {
module.exports.helmet.contentSecurityPolicy.directives.scriptSrc.push(`'nonce-browsersync'`);
module.exports.helmet.contentSecurityPolicy.directives.connectSrc.push("http:");
}
module.exports.morgan = {
stream: process.stdout
};
module.exports.serverInfo = {
host: process.env.HOST || "localhost",
port: process.env.PORT || 80,
};
module.exports.storage = {
provider: process.env.STORAGE || appConfig.storage.provider,
options: tryDo(JSON.parse, process.env.STORAGE_OPTS) || appConfig.storage.options
};
module.exports.java = {
java: appConfig.java.java || "java",
compiler: appConfig.java.compiler || "javac",
};
function tryDo(fn, param, thisArg) {
try {
if(!!param) return fn.call(thisArg, param);
} catch(e) {}
return false;
}
function tryNew(clazz, param) {
try {
if(!!param) return new clazz(param);
} catch(e) {}
return false;
}