From c3acf81166d8fd11279ed36a93b1c0f7fd318ddb Mon Sep 17 00:00:00 2001
From: Alexandre Alapetite
Date: Thu, 12 Oct 2023 23:31:52 +0200
Subject: [PATCH 1/4] change image links from public to local Apply
https://github.com/endemecio02/node-red-contrib-httpauth/pull/3 from
@sakazuki
---
nodes/http-auth.html | 2 +-
nodes/http-auth.js | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/nodes/http-auth.html b/nodes/http-auth.html
index 1cb2bdd..cfa545b 100644
--- a/nodes/http-auth.html
+++ b/nodes/http-auth.html
@@ -71,7 +71,7 @@
-
+
Config
diff --git a/nodes/http-auth.js b/nodes/http-auth.js
index e8db485..ff3445a 100644
--- a/nodes/http-auth.js
+++ b/nodes/http-auth.js
@@ -99,4 +99,25 @@ module.exports = function (RED) {
}
RED.nodes.registerType('http-basic-auth', HttpAuthNode);
+
+ if (RED.httpAdmin) {
+ const fs = require('fs');
+ const path = require('path');
+ RED.httpAdmin.get('/node-red-http-basic-auth/images/:file', function (req, res, next) {
+ const filename = req.params.file.replace(/[^a-zA-Z0-9._-]/g, '').replace(/^\.+/g, '');
+ fs.readFile(path.join(__dirname, '/../images/', filename), function (err, data) {
+ if (err) {
+ res.status(404).end();
+ } else {
+ res.set('Content-Type', 'image/png');
+ res.send(data, function (err) {
+ if (err) {
+ console.warn('Error serving image:', err);
+ res.status(500).end();
+ }
+ });
+ }
+ });
+ });
+ }
};
From 633dafa545bebd7217ac8bb93c63660f1b2cada4 Mon Sep 17 00:00:00 2001
From: Alexandre Alapetite
Date: Thu, 12 Oct 2023 23:49:59 +0200
Subject: [PATCH 2/4] Fix path join
---
nodes/http-auth.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/nodes/http-auth.js b/nodes/http-auth.js
index ff3445a..06d1c6b 100644
--- a/nodes/http-auth.js
+++ b/nodes/http-auth.js
@@ -105,8 +105,10 @@ module.exports = function (RED) {
const path = require('path');
RED.httpAdmin.get('/node-red-http-basic-auth/images/:file', function (req, res, next) {
const filename = req.params.file.replace(/[^a-zA-Z0-9._-]/g, '').replace(/^\.+/g, '');
- fs.readFile(path.join(__dirname, '/../images/', filename), function (err, data) {
+ const imagePath = path.join(__dirname, '..', 'images', filename);
+ fs.readFile(imagePath, function (err, data) {
if (err) {
+ console.warn('Error reading image:', err);
res.status(404).end();
} else {
res.set('Content-Type', 'image/png');
From 720134110f8d5cbc8870ee33349b94d4a5e1f41e Mon Sep 17 00:00:00 2001
From: Alexandre Alapetite
Date: Fri, 13 Oct 2023 00:01:22 +0200
Subject: [PATCH 3/4] Use Express built-in methods
---
nodes/http-auth.js | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/nodes/http-auth.js b/nodes/http-auth.js
index 06d1c6b..4c67613 100644
--- a/nodes/http-auth.js
+++ b/nodes/http-auth.js
@@ -101,23 +101,16 @@ module.exports = function (RED) {
RED.nodes.registerType('http-basic-auth', HttpAuthNode);
if (RED.httpAdmin) {
- const fs = require('fs');
const path = require('path');
- RED.httpAdmin.get('/node-red-http-basic-auth/images/:file', function (req, res, next) {
- const filename = req.params.file.replace(/[^a-zA-Z0-9._-]/g, '').replace(/^\.+/g, '');
- const imagePath = path.join(__dirname, '..', 'images', filename);
- fs.readFile(imagePath, function (err, data) {
+ RED.httpAdmin.get('/node-red-http-basic-auth/images/:name', (req, res, next) => {
+ const options = {
+ root: path.join(__dirname, '..', 'images'),
+ dotfiles: 'deny',
+ };
+ const fileName = req.params.name;
+ res.sendFile(fileName, options, function (err) {
if (err) {
- console.warn('Error reading image:', err);
- res.status(404).end();
- } else {
- res.set('Content-Type', 'image/png');
- res.send(data, function (err) {
- if (err) {
- console.warn('Error serving image:', err);
- res.status(500).end();
- }
- });
+ next(err);
}
});
});
From a081efec1f999b8e623914fa140b01a804d92b61 Mon Sep 17 00:00:00 2001
From: Alexandre Alapetite
Date: Fri, 13 Oct 2023 00:06:46 +0200
Subject: [PATCH 4/4] Minor syntax
---
nodes/http-auth.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nodes/http-auth.js b/nodes/http-auth.js
index 4c67613..e820737 100644
--- a/nodes/http-auth.js
+++ b/nodes/http-auth.js
@@ -108,7 +108,7 @@ module.exports = function (RED) {
dotfiles: 'deny',
};
const fileName = req.params.name;
- res.sendFile(fileName, options, function (err) {
+ res.sendFile(fileName, options, (err) => {
if (err) {
next(err);
}