mrfrys-node-server/server.js
YourFriendlyNeighborhoodDealer 3123a9bf10 Log line every day
2019-08-19 10:52:58 +02:00

107 lines
3.1 KiB
JavaScript

/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/YourFriendlyNeighborhoodDealer/question-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
const express = require('express')
const vhost = require('vhost')
const logger = require('./utils/logger.js')
const utils = require('./utils/utils.js')
const stat = require('./utils/stat.js')
stat.Load()
const qmining = require('./modules/qmining.js').app
const main = require('./modules/main.js').app
const sio = require('./modules/sio.js').app
const stuff = require('./modules/stuff.js').app
const port = 8080
const locLogFile = './stats/logs'
const allLogFile = '/nlogs/log'
// // https://certbot.eff.org/
// const privkeyFile = '/etc/letsencrypt/live/qmining.tk/privkey.pem'
// const fullchainFile = '/etc/letsencrypt/live/qmining.tk/fullchain.pem'
// const chainFile = '/etc/letsencrypt/live/qmining.tk/chain.pem'
//
// var certsLoaded = false
// if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists(
// chainFile)) {
// try {
// const key = fs.readFileSync(privkeyFile, 'utf8')
// const cert = fs.readFileSync(fullchainFile, 'utf8')
// const ca = fs.readFileSync(chainFile, 'utf8')
// var certs = {
// key: key,
// cert: cert,
// ca: ca
// }
// certsLoaded = true
// } catch (e) {
// logger.Log('Error loading cert files!', logger.GetColor('redbg'))
// }
// }
function setLogTimer () {
const d = new Date()
const h = new Date(
d.getFullYear(),
d.getMonth(),
d.getDate() + 1,
0,
0,
0,
0
)
const e = h - d
if (e > 100) {
setTimeout(setLogTimer, e)
} else {
logger.Log('Log timer malfunction :/')
}
const line = '-------------------------------------------------------------------------------'
logger.Log(line)
utils.AppendToFile(line, locLogFile)
utils.AppendToFile(line, allLogFile)
}
setLogTimer()
const app = express()
app.use(function (req, res, next) {
res.on('finish', function () {
logger.LogReq(req, true, res.statusCode)
if (res.statusCode !== 404) { stat.LogStat(req.url) }
})
next()
})
app.use(vhost('qmining.frylabs.net', qmining))
app.use(vhost('sio.frylabs.net', sio))
app.use(vhost('stuff.frylabs.net', stuff))
app.use(vhost('frylabs.net', main))
app.use(vhost('qmining.tk', qmining))
app.listen(port)
logger.Log('Node version: ' + process.version)
logger.Log('Listening on port: ' + port)