mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Https
This commit is contained in:
parent
3123a9bf10
commit
ada8b71804
1 changed files with 45 additions and 24 deletions
69
server.js
69
server.js
|
@ -18,10 +18,17 @@
|
||||||
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const startHTTPS = true
|
||||||
|
const port = 8080
|
||||||
|
const httpsport = 8443
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const vhost = require('vhost')
|
const vhost = require('vhost')
|
||||||
const logger = require('./utils/logger.js')
|
const logger = require('./utils/logger.js')
|
||||||
const utils = require('./utils/utils.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')
|
const stat = require('./utils/stat.js')
|
||||||
stat.Load()
|
stat.Load()
|
||||||
|
|
||||||
|
@ -29,33 +36,34 @@ const qmining = require('./modules/qmining.js').app
|
||||||
const main = require('./modules/main.js').app
|
const main = require('./modules/main.js').app
|
||||||
const sio = require('./modules/sio.js').app
|
const sio = require('./modules/sio.js').app
|
||||||
const stuff = require('./modules/stuff.js').app
|
const stuff = require('./modules/stuff.js').app
|
||||||
|
const local = require('./modules/local.js').app
|
||||||
|
|
||||||
const port = 8080
|
|
||||||
const locLogFile = './stats/logs'
|
const locLogFile = './stats/logs'
|
||||||
const allLogFile = '/nlogs/log'
|
const allLogFile = '/nlogs/log'
|
||||||
|
|
||||||
// // https://certbot.eff.org/
|
// https://certbot.eff.org/
|
||||||
// const privkeyFile = '/etc/letsencrypt/live/qmining.tk/privkey.pem'
|
const privkeyFile = '/etc/letsencrypt/live/frylabs.net/privkey.pem'
|
||||||
// const fullchainFile = '/etc/letsencrypt/live/qmining.tk/fullchain.pem'
|
const fullchainFile = '/etc/letsencrypt/live/frylabs.net/fullchain.pem'
|
||||||
// const chainFile = '/etc/letsencrypt/live/qmining.tk/chain.pem'
|
const chainFile = '/etc/letsencrypt/live/frylabs.net/chain.pem'
|
||||||
//
|
|
||||||
// var certsLoaded = false
|
var certsLoaded = false
|
||||||
// if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists(
|
if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFile) && utils.FileExists(
|
||||||
// chainFile)) {
|
chainFile)) {
|
||||||
// try {
|
try {
|
||||||
// const key = fs.readFileSync(privkeyFile, 'utf8')
|
const key = fs.readFileSync(privkeyFile, 'utf8')
|
||||||
// const cert = fs.readFileSync(fullchainFile, 'utf8')
|
const cert = fs.readFileSync(fullchainFile, 'utf8')
|
||||||
// const ca = fs.readFileSync(chainFile, 'utf8')
|
const ca = fs.readFileSync(chainFile, 'utf8')
|
||||||
// var certs = {
|
var certs = {
|
||||||
// key: key,
|
key: key,
|
||||||
// cert: cert,
|
cert: cert,
|
||||||
// ca: ca
|
ca: ca
|
||||||
// }
|
}
|
||||||
// certsLoaded = true
|
certsLoaded = true
|
||||||
// } catch (e) {
|
} catch (e) {
|
||||||
// logger.Log('Error loading cert files!', logger.GetColor('redbg'))
|
logger.Log('Error loading cert files!', logger.GetColor('redbg'))
|
||||||
// }
|
console.log(e)
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setLogTimer () {
|
function setLogTimer () {
|
||||||
const d = new Date()
|
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('stuff.frylabs.net', stuff))
|
||||||
app.use(vhost('frylabs.net', main))
|
app.use(vhost('frylabs.net', main))
|
||||||
app.use(vhost('qmining.tk', qmining))
|
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('Node version: ' + process.version)
|
||||||
logger.Log('Listening on port: ' + port)
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue