-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
66 lines (56 loc) · 1.53 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
require("dotenv").config();
const forceDev = false;
module.exports = {};
module.exports.db = {
url: tryNew(URL, process.env.MYSQL_URL) || ""
};
module.exports.session = {
secret: process.env.SESSION_SECRET || "secret",
cookieName: process.env.SESSION_COOKIE || "session",
};
module.exports.env = {
node: process.env.NODE_ENV || "production",
isDev: forceDev
};
module.exports.env.isDev = module.exports.env.node.startsWith("dev") || forceDev;
module.exports.helmet = {
contentSecurityPolicy: {
useDefaults: true,
directives: {
defaultSrc: ["'self'", "http:"],
scriptSrc: [
"'self'",
// add any extra sources here!
module.exports.env.isDev ? `'nonce-browsersync'` : "",
(req, res) => `'nonce-${res.locals.nonce}'`,
],
workerSrc: ["'self'", "blob:"],
upgradeInsecureRequests: null
}
}
};
module.exports.morgan = {
stream: process.stdout
};
module.exports.serverInfo = {
host: process.env.HOST,
port: parseInt(process.env.PORT || 80)
};
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;
}
function tryRequire(module) {
try {
return require(module);
} catch(e) {}
return {};
}