From 911835821eb5243cca14dc5a89d64061a4e6708d Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Tue, 27 Jun 2023 03:01:19 +0200 Subject: [PATCH] Dodal https support --- .gitignore | 4 +++- app.js | 28 ++++++++++++++++++++++++---- package-lock.json | 18 ++++++++++++++++++ package.json | 3 +++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index fbec6a6..6e8d318 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,6 @@ typings/ # next.js build output .next -UpImage/ \ No newline at end of file +UpImage/ + +archive/ \ No newline at end of file diff --git a/app.js b/app.js index cf6beb2..07b8d70 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,19 @@ var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); +const http = require('http'); +const https = require('https'); +const fs = require('fs'); +const hostname = 'petrov.nexus'; +const httpPort = 80; +const httpsPort = 443; + +const httpsOptions = { + key: fs.readFileSync('./archive/server.key'), + cert: fs.readFileSync('./archive/petrov_nexus.crt'), + ca: fs.readFileSync('./archive/petrov_nexus.ca-bundle') +}; // vključimo mongoose in ga povežemo z MongoDB var mongoose = require('mongoose'); @@ -23,6 +35,9 @@ var movieShowRouter = require('./routes/movies/movieShow'); var app = express(); +const httpServer = http.createServer(app); +const httpsServer = https.createServer(httpsOptions, app); + // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); @@ -78,9 +93,14 @@ app.use(function(err, req, res, next) { res.render('error', {title:'Error'}); }); -const port = 80; -app.listen(port, () => { - console.log(`Example app listening on port ${port}`) -}) +httpServer.listen(httpPort, () => { + console.log(`Server running at http://${hostname}:${httpPort}/`); +}); +httpsServer.listen(httpsPort, () => { + console.log(`Server running at https://${hostname}:${httpsPort}/`); +}); + + + module.exports = app; diff --git a/package-lock.json b/package-lock.json index b98f504..da93056 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,11 @@ "debug": "~2.6.9", "express": "^4.18.2", "express-session": "^1.17.3", + "fs": "^0.0.1-security", "hbs": "^4.2.0", + "http": "^0.0.1-security", "http-errors": "~1.6.3", + "https": "^1.0.0", "mongoose": "^7.3.1", "morgan": "~1.9.1", "multer": "^1.4.5-lts.1" @@ -607,6 +610,11 @@ "node": ">= 0.6" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -692,6 +700,11 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/http": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", + "integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==" + }, "node_modules/http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", @@ -706,6 +719,11 @@ "node": ">= 0.6" } }, + "node_modules/https": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz", + "integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg==" + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index 4f9676d..6d27cf8 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,11 @@ "debug": "~2.6.9", "express": "^4.18.2", "express-session": "^1.17.3", + "fs": "^0.0.1-security", "hbs": "^4.2.0", + "http": "^0.0.1-security", "http-errors": "~1.6.3", + "https": "^1.0.0", "mongoose": "^7.3.1", "morgan": "~1.9.1", "multer": "^1.4.5-lts.1"