mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added https support
This commit is contained in:
parent
e8945185e2
commit
05b034974c
1 changed files with 22 additions and 2 deletions
24
server.js
24
server.js
|
@ -23,6 +23,8 @@ var bodyParser = require('body-parser');
|
|||
var busboy = require('connect-busboy');
|
||||
var fs = require('fs');
|
||||
var app = express();
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
var logger = require('./logger.js');
|
||||
var utils = require('./utils.js');
|
||||
|
@ -41,7 +43,14 @@ const simpOutFile = "public/simplified";
|
|||
const inputFile = "stats/inputs";
|
||||
const msgFile = "stats/msgs";
|
||||
const logFile = "stats/logs";
|
||||
|
||||
// https://certbot.eff.org/
|
||||
const key = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/privkey.pem", "utf8");
|
||||
const cert = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/fullchain.pem", "utf8");
|
||||
const ca = fs.readFileSync("/etc/letsencrypt/live/questionmining.tk/chain.pem", "utf8");
|
||||
var certs = {key:key, cert:cert, ca:ca};
|
||||
const port = 8080;
|
||||
const httpsPort = 8443;
|
||||
|
||||
var highlights = ["public", "static", "manual", "isgetting", "postfeedback",
|
||||
"postquestions"
|
||||
|
@ -66,6 +75,13 @@ try {
|
|||
var newMessages = "";
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
//app.all('*', function(req, res, next) {
|
||||
// if(req.secure) {
|
||||
// next();
|
||||
// } else {
|
||||
// res.redirect('https://' + req.hostname + req.url);
|
||||
// }
|
||||
//});
|
||||
app.use(function(req, res, next) {
|
||||
res.on('finish', function() {
|
||||
Log(req, true);
|
||||
|
@ -203,14 +219,18 @@ app.post('*', function(req, res) {
|
|||
});
|
||||
|
||||
stat.Load();
|
||||
app.listen(port);
|
||||
const httpServer = http.createServer(app);
|
||||
const httpsServer = https.createServer(certs, app);
|
||||
httpServer.listen(port);
|
||||
httpsServer.listen(httpsPort);
|
||||
logger.Log("[STRT]: Server listening on port " + port + "...", logger.GetColor("yellow"));
|
||||
|
||||
function Log(req, toFile) {
|
||||
try {
|
||||
var ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress;
|
||||
var logEntry = "[RSND]: " + ip + ", " + req.headers['user-agent'] +
|
||||
" " + req.method + " " + req.url;
|
||||
" " + req.method + " ";
|
||||
logEntry += req.url;
|
||||
var color = logger.GetColor("green");
|
||||
for (var i = 0; i < highlights.length; i++)
|
||||
if (req.url.toLowerCase().includes(highlights[i])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue