This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-08-20 11:11:40 +02:00
parent 3123a9bf10
commit ada8b71804

View file

@ -18,10 +18,17 @@
------------------------------------------------------------------------- */
const startHTTPS = true
const port = 8080
const httpsport = 8443
const express = require('express')
const vhost = require('vhost')
const logger = require('./utils/logger.js')
const utils = require('./utils/utils.js')
const fs = require('fs');
const http = require('http');
const https = require('https');
const stat = require('./utils/stat.js')
stat.Load()
@ -29,33 +36,34 @@ 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 local = require('./modules/local.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'))
// }
// }
// https://certbot.eff.org/
const privkeyFile = '/etc/letsencrypt/live/frylabs.net/privkey.pem'
const fullchainFile = '/etc/letsencrypt/live/frylabs.net/fullchain.pem'
const chainFile = '/etc/letsencrypt/live/frylabs.net/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'))
console.log(e)
}
}
function setLogTimer () {
const d = new Date()
@ -100,8 +108,21 @@ 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.use(vhost('*.*', local))
app.use(vhost('192.168.0.2', local))
app.listen(port)
logger.Log('Node version: ' + process.version)
logger.Log('Listening on port: ' + port)
const httpServer = http.createServer(app);
httpServer.listen(port);
if (certsLoaded) {
const httpsServer = https.createServer(certs, app);
httpsServer.listen(httpsport);
logger.Log('Listening on port: ' + httpsport + ' (https)')
} else {
logger.Log('Https not avaible')
}
// app.listen(port)