-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
155 lines (140 loc) · 5.31 KB
/
options.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
// Thirtd-party libraries
exports.env = require('dotenv').config().parsed; // First of all load environment
const fs = require("fs"); // Filesystem
// Root folder
exports.root = __dirname;
// Server state
const state = exports.state = {
startup_time: Date.now(),
debug: (process.env.NODE_ENVIRONMENT.toLowerCase() == 'dev' || process.argv.indexOf('--env-dev') !== -1),
isMasterThread: ( // For cluster mode
(process.env['NODE APP INSTANCE'] && process.env['NODE APP INSTANCE'] === '0') ||
(process.env.NODE_APP_INSTANCE && process.env.NODE_APP_INSTANCE === '0') ||
(process.env.NODE_APP_INSTANCE === undefined && process.env['NODE APP INSTANCE'] === undefined)
)
}
// General data
exports.host = `http${state.debug ? '' : 's'}://${process.env.NODE_HOST ? process.env.NODE_HOST : 'localhost'}/`;
exports.secret = process.env.NODE_APP_SECRET;
exports.port = {
http: 80,
https: 443
};
// Contacts
exports.contacts = {
email: {
appointment: process.env.NODE_CONTACT_EMAIL_APPOINTMENT ? process.env.NODE_CONTACT_EMAIL_APPOINTMENT : process.env.NODE_SMTP_LOGIN
}
}
// SSL Options
exports.ssl = state.debug ? {} : {
key: fs.readFileSync('SSL/' + (process.env.NODE_SSL_KEY_NAME ? process.env.NODE_SSL_KEY_NAME : 'certificate.key')),
cert: fs.readFileSync('SSL/' + (process.env.NODE_SSL_CRT_NAME ? process.env.NODE_SSL_CRT_NAME : 'certificate.crt')),
requestCert: false,
rejectUnauthorized: false,
};
// Database connection
const Sequelize = require('sequelize'); // library for mapping models
exports.db = {
sync: {
allow_force: (process.env.NODE_SEQUELIZE_ALLOW_FORCE_SYNC === 'true'),
allow_alter: (process.env.NODE_SEQUELIZE_ALLOW_ALTER_SYNC === 'true')
},
sequelize: new Sequelize(
process.env.NODE_SEQUELIZE_DB_NAME,
process.env.NODE_SEQUELIZE_DB_USERNAME ? process.env.NODE_SEQUELIZE_DB_USERNAME : '',
process.env.NODE_SEQUELIZE_DB_PASSWORD ? process.env.NODE_SEQUELIZE_DB_PASSWORD : '',
{
host: process.env.NODE_SEQUELIZE_DB_HOST ? process.env.NODE_SEQUELIZE_DB_HOST : '127.0.0.1',
dialect: process.env.NODE_SEQUELIZE_DIALECT,
logging: (state.debug && process.env.NODE_SEQUELIZE_PRINT_DEBUG != 'false' || process.env.NODE_SEQUELIZE_PRINT_DEBUG == 'true')
? (message) => console.log(`\x1b[35m${message}\x1b[0m`)
: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
define: {
timestamps: false, // only columun name you have, without = id, createdAt, updatedAt
freezeTableName: true // only table name you have, without = tablename(s)
}
}),
mongoDB: {
dbString: process.env.NODE_MONGO_DB_CONNECTION_STRING,
dbNames: process.env.NODE_MONGO_DB_DBNAMES.split(',')
}
}
// Email
const nodemailer = require('nodemailer');
exports.mailerTransport = nodemailer.createTransport({
host: process.env.NODE_SMTP_HOST,
port: process.env.NODE_SMTP_PORT ? Number(process.env.NODE_SMTP_PORT) : 465,
secure: true, // use TLS
auth: {
user: process.env.NODE_SMTP_LOGIN,
pass: process.env.NODE_SMTP_PASSWORD
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
}
});
// Init server
const initScripts = require('./init');
exports.init = (callback) => {
initScripts.startInitialize(state.isMasterThread, callback,
initScripts.initSequelize(exports.db.sequelize),
initScripts.syncDBTables(`${exports.root}/Models`, { force: false, alter: true }),
initScripts.initMailer(exports.mailerTransport)
);
}
// Session settings
exports.session = {
secretKey: process.env.NODE_SESSION_SECRET,
TTL: process.env.NODE_SESSION_ALIVE ? Number(process.env.NODE_SESSION_ALIVE) : (24 * 60 * 60 * 1000),
middleware: () => require('./Middlewares/session/cookieSessionMiddleware')
};
// Redis settings
exports.redis = {
host: process.env.NODE_REDIS_HOST ? process.env.NODE_REDIS_HOST : '127.0.0.1',
port: process.env.NODE_REDIS_PORT ? Number(process.env.NODE_REDIS_PORT) : 6379,
secretKey: process.env.NODE_REDIS_SECRET
}
// A settings
exports.integrations = {
vk: {
appID: process.env.NODE_VK_APP_ID,
appSecret: process.env.NODE_VK_APP_SECRET
},
facebook: {
appID: process.env.NODE_FB_APP_ID,
appSecret: process.env.NODE_FB_APP_SECRET
},
google: {
appID: process.env.NODE_GOOGLE_CLIENT_ID,
appSecret: process.env.NODE_GOOGLE_CLENT_SECRET
}
}
// Cookie Settings
exports.cookiesecretKey = process.env.NODE_COOKIES_SECRET;
exports.cookieSettings = () => { return { expires: new Date(Date.now() + Number(process.env.NODE_COOKIES_ALIVE)), signed: true } };
// Static config
exports.staticServeOptions = {
dotfiles: 'ignore',
etag: false,
extensions: ['htm', 'html'],
fallthrough: true,
index: false,
maxAge: '1d',
redirect: false,
setHeaders: function (res, path, stat) {
res.set('x-timestamp', Date.now())
}
}
// Git Webhooks Secret
exports.gitWebhooksSecret = process.env.NODE_GIT_WEBHOOK_SECRET;
exports.gitWebhooksReference = process.env.NODE_GIT_WEBHOOK_REFERENCE;
exports.reloadScriptName = 'lin_reload_pm2.sh';