From e34bf18e97a61dfca0ea95fbd442cb9c9e1a8e5f Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 21:23:50 +0200 Subject: [PATCH 1/7] updated eslint to stop marking __dirname --- backend/eslint.config.mjs | 3 +++ frontend/eslint.config.mjs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/eslint.config.mjs b/backend/eslint.config.mjs index b917886..0ddecdf 100644 --- a/backend/eslint.config.mjs +++ b/backend/eslint.config.mjs @@ -24,6 +24,9 @@ export default defineConfig([ "variables": true, "allowNamedExports": false }] + }, + languageOptions: { + globals: { ...globals.node } } } diff --git a/frontend/eslint.config.mjs b/frontend/eslint.config.mjs index c4e2ee3..5e8102e 100644 --- a/frontend/eslint.config.mjs +++ b/frontend/eslint.config.mjs @@ -26,7 +26,7 @@ export default defineConfig([ }] }, languageOptions: { - globals: { ...globals.browser, ...globals.jquery } + globals: { ...globals.browser, ...globals.jquery, ...globals.node } } } From 930c59f711f2207a0a2fcf20a78083a7b3b3c375 Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:32:01 +0200 Subject: [PATCH 2/7] #51 replaceMiddleware WIP --- frontend/client.js | 4 ++- frontend/middleware/replaceMiddleware.js | 35 ++++++++++++++++++++++++ frontend/templates/test.html | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 frontend/middleware/replaceMiddleware.js create mode 100644 frontend/templates/test.html diff --git a/frontend/client.js b/frontend/client.js index 7b5e954..b6cd9b8 100644 --- a/frontend/client.js +++ b/frontend/client.js @@ -21,12 +21,14 @@ try const HTTP_PORT = 8000; const express = require('express'); //const morgan = require('morgan'); + const replaceMiddleware = require('./middleware/replaceMiddleware'); console.log('Creating and configuring Web Server...'); const app = express(); console.log('Binding middleware...'); - app.use(express.static('./public')) + app.use(replaceMiddleware); + app.use(express.static('./public')); app.use(function(request, response, next) { response.setHeader('Access-Control-Allow-Origin', '*'); response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE'); diff --git a/frontend/middleware/replaceMiddleware.js b/frontend/middleware/replaceMiddleware.js new file mode 100644 index 0000000..7193e68 --- /dev/null +++ b/frontend/middleware/replaceMiddleware.js @@ -0,0 +1,35 @@ +const fs = require('fs'); +const path = require('path'); + +function replaceMiddleware(req, res, next) { + let requestedFile = req.path; + + // Wenn Root angefragt wird, auf index.html umleiten + if (requestedFile === '/' || requestedFile === '') { + requestedFile = '/index.html'; + } + + if (requestedFile.endsWith('.html')) { + console.log("replaceMiddleware"); + const filePath = path.join(__dirname, '../public', requestedFile); + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.log("Error in replaceMiddleware: could not find " + filePath); + return next(); + } + fs.readFile(path.join(__dirname, '../templates', 'test.html'), 'utf8', (testErr, testContent) => { + if (testErr){ + testContent = ''; + console.log("Error in replaceMiddleware: could not find file test.html"); + } + const replaced = data.replace('', testContent); + res.setHeader('Content-Type', 'text/html'); + res.send(replaced); + }); + }); + } else { + next(); + } +} + +module.exports = replaceMiddleware; \ No newline at end of file diff --git a/frontend/templates/test.html b/frontend/templates/test.html new file mode 100644 index 0000000..58095ee --- /dev/null +++ b/frontend/templates/test.html @@ -0,0 +1 @@ +

Das ist voll der mega Test Alda

\ No newline at end of file From dc5305a077e6246cec7249ca3742cdc9480cf990 Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:32:49 +0200 Subject: [PATCH 3/7] #51 updated replaceMiddleware to support multiple markers --- frontend/middleware/replaceMiddleware.js | 68 ++++++++++++++++++------ 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/frontend/middleware/replaceMiddleware.js b/frontend/middleware/replaceMiddleware.js index 7193e68..b3e41d1 100644 --- a/frontend/middleware/replaceMiddleware.js +++ b/frontend/middleware/replaceMiddleware.js @@ -1,6 +1,14 @@ const fs = require('fs'); const path = require('path'); +// Mapping: Marker => Datei +const replacements = { + '': path.join(__dirname, '../templates/nav.html'), + '': path.join(__dirname, '../templates/commonHead.html'), + '': path.join(__dirname, '../templates/bottomScripts.html'), + // weitere Marker und Dateien hier ergänzen +}; + function replaceMiddleware(req, res, next) { let requestedFile = req.path; @@ -9,27 +17,53 @@ function replaceMiddleware(req, res, next) { requestedFile = '/index.html'; } - if (requestedFile.endsWith('.html')) { - console.log("replaceMiddleware"); - const filePath = path.join(__dirname, '../public', requestedFile); - fs.readFile(filePath, 'utf8', (err, data) => { - if (err) { - console.log("Error in replaceMiddleware: could not find " + filePath); - return next(); + // Wenn es kein HTML ist skip + if (!requestedFile.endsWith('.html')) { + return next(); + } + + console.log(`replaceMiddleware running for ${requestedFile}`); + + const filePath = path.join(__dirname, '../public', requestedFile); + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.log("Error in replaceMiddleware: could not find " + filePath); + return next(); + } + + // Alle Marker ersetzen + const markers = Object.keys(replacements); + let pending = markers.length; + let replacedData = data; + + if (pending === 0) { + res.setHeader('Content-Type', 'text/html'); + return res.send(replacedData); + } + + markers.forEach(marker => { + + if(!replacedData.includes(marker)) + { + pending--; + return; //hier wie continue } - fs.readFile(path.join(__dirname, '../templates', 'test.html'), 'utf8', (testErr, testContent) => { - if (testErr){ - testContent = ''; - console.log("Error in replaceMiddleware: could not find file test.html"); + + fs.readFile(replacements[marker], 'utf8', (fileErr, fileContent) => { + if (fileErr) { + console.log(`Error in replaceMiddleware: could not find file for marker ${marker}`); + } + else { + replacedData = replacedData.replace(marker, fileContent); + } + pending--; + if (pending <= 0) { + res.setHeader('Content-Type', 'text/html'); + res.send(replacedData); } - const replaced = data.replace('', testContent); - res.setHeader('Content-Type', 'text/html'); - res.send(replaced); }); }); - } else { - next(); - } + }); } module.exports = replaceMiddleware; \ No newline at end of file From c9e34ced5018f11d3733516d74f2abd98a0bbc70 Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:33:33 +0200 Subject: [PATCH 4/7] #51 updated index.html to make use of the replaceMiddleware --- frontend/public/index.html | 46 ++------------------------- frontend/templates/bottomScripts.html | 3 ++ frontend/templates/commonHead.html | 13 ++++++++ frontend/templates/nav.html | 26 +++++++++++++++ frontend/templates/test.html | 1 - 5 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 frontend/templates/bottomScripts.html create mode 100644 frontend/templates/commonHead.html create mode 100644 frontend/templates/nav.html delete mode 100644 frontend/templates/test.html diff --git a/frontend/public/index.html b/frontend/public/index.html index 6115839..945b404 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -2,57 +2,19 @@ - - - + Dashboard - Plant Manager - - - - - - - - - - - +
-
@@ -66,8 +28,6 @@
- - - + \ No newline at end of file diff --git a/frontend/templates/bottomScripts.html b/frontend/templates/bottomScripts.html new file mode 100644 index 0000000..fde4033 --- /dev/null +++ b/frontend/templates/bottomScripts.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/frontend/templates/commonHead.html b/frontend/templates/commonHead.html new file mode 100644 index 0000000..0171232 --- /dev/null +++ b/frontend/templates/commonHead.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/templates/nav.html b/frontend/templates/nav.html new file mode 100644 index 0000000..ce24764 --- /dev/null +++ b/frontend/templates/nav.html @@ -0,0 +1,26 @@ + \ No newline at end of file diff --git a/frontend/templates/test.html b/frontend/templates/test.html deleted file mode 100644 index 58095ee..0000000 --- a/frontend/templates/test.html +++ /dev/null @@ -1 +0,0 @@ -

Das ist voll der mega Test Alda

\ No newline at end of file From 8b7d52637c232c2f979cf01a8003879d364364ff Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:35:21 +0200 Subject: [PATCH 5/7] #51 added template --- frontend/public/dev/template.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 frontend/public/dev/template.html diff --git a/frontend/public/dev/template.html b/frontend/public/dev/template.html new file mode 100644 index 0000000..c564509 --- /dev/null +++ b/frontend/public/dev/template.html @@ -0,0 +1,26 @@ + + + + + + + EDIT - Plant Manager + + + + + + + + + +
+ + + + +
+ + + + \ No newline at end of file From 371fa08dcd3ba1f72cd4b277f53de5e95f2fa483 Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:43:02 +0200 Subject: [PATCH 6/7] #51 edited remaining pages to make use of the replaceMiddleware --- frontend/public/detailseite_pflanze.html | 45 ++------------------- frontend/public/dev/index.html | 46 ++------------------- frontend/public/kompostierte_pflanzen.html | 45 ++------------------- frontend/public/meine_pflanzen.html | 45 ++------------------- frontend/public/pflanze_bearbeiten.html | 47 ++-------------------- 5 files changed, 16 insertions(+), 212 deletions(-) diff --git a/frontend/public/detailseite_pflanze.html b/frontend/public/detailseite_pflanze.html index de3a125..d228fff 100644 --- a/frontend/public/detailseite_pflanze.html +++ b/frontend/public/detailseite_pflanze.html @@ -2,54 +2,17 @@ - - - + Plant Manager - - - - - - - - - - - +
@@ -122,8 +85,6 @@

- - - + \ No newline at end of file diff --git a/frontend/public/dev/index.html b/frontend/public/dev/index.html index d122a6b..f2798d7 100644 --- a/frontend/public/dev/index.html +++ b/frontend/public/dev/index.html @@ -2,54 +2,17 @@ - - - + Plant Manager - - - - - - - - - - - +
@@ -62,8 +25,5 @@

Dev Page

- - - - + \ No newline at end of file diff --git a/frontend/public/kompostierte_pflanzen.html b/frontend/public/kompostierte_pflanzen.html index 5760fea..2dea55f 100644 --- a/frontend/public/kompostierte_pflanzen.html +++ b/frontend/public/kompostierte_pflanzen.html @@ -2,54 +2,17 @@ - - - + Plant Manager - Kompost - - - - - - - - - - - +
@@ -104,8 +67,6 @@

Kompost

- - - + \ No newline at end of file diff --git a/frontend/public/meine_pflanzen.html b/frontend/public/meine_pflanzen.html index efb7e19..e2eaf8b 100644 --- a/frontend/public/meine_pflanzen.html +++ b/frontend/public/meine_pflanzen.html @@ -2,54 +2,17 @@ - - - + Plant Manager - - - - - - - - - - - +
@@ -69,8 +32,6 @@
- - - + \ No newline at end of file diff --git a/frontend/public/pflanze_bearbeiten.html b/frontend/public/pflanze_bearbeiten.html index b00c07a..21625bf 100644 --- a/frontend/public/pflanze_bearbeiten.html +++ b/frontend/public/pflanze_bearbeiten.html @@ -2,53 +2,16 @@ - - - + - Plant Manager - - - - - - - - - - + Plant Manager - Pflanze bearbeiten - +
@@ -124,8 +87,6 @@
- - - + \ No newline at end of file From ffc217bd90f2f4d40123a652397cd7e25f011cf5 Mon Sep 17 00:00:00 2001 From: CoderTobi <77673526+CoderTobi@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:04:49 +0200 Subject: [PATCH 7/7] #51 Added back highlighting of the active page to the navbar --- frontend/templates/nav.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/templates/nav.html b/frontend/templates/nav.html index ce24764..a5efbae 100644 --- a/frontend/templates/nav.html +++ b/frontend/templates/nav.html @@ -23,4 +23,13 @@ + \ No newline at end of file