Skip to content

Commit

Permalink
feat(webserver): Add X-Valetudo-Version header
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Apr 24, 2021
1 parent a18633c commit d494510
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/webserver/WebServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const listEndpoints = require("express-list-endpoints");

const Logger = require("../Logger");

const Middlewares = require("./middlewares");
const RobotRouter = require("./RobotRouter");
const ValetudoRouter = require("./ValetudoRouter");

Expand Down Expand Up @@ -39,6 +40,9 @@ class WebServer {
this.app.use(compression());
this.app.use(bodyParser.json());

this.app.disable("x-powered-by");
this.app.use(Middlewares.VersionMiddleware);

const authMiddleware = this.createAuthMiddleware();
const dynamicAuth = dynamicMiddleware.create([]);
this.app.use(dynamicAuth.handle());
Expand Down
25 changes: 25 additions & 0 deletions lib/webserver/middlewares/VersionMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Tools = require("../../Tools");

const version = Tools.GET_VALETUDO_VERSION();
const commitId = Tools.GET_COMMIT_ID();
/**
* The main purpose of these headers is to make it easier
* to find internet-facing valetudo instances using shodan.io
* so that I can be mad about them
*
* Don't do that.
* Use a VPN or at least a reverse-proxy with proper auth.
*
* By ignoring this warning, you opt-in to valetudo
* telemetry data collection via the cloud
*
*
* @param {object} req
* @param {object} res
* @param {Function} next
*/
module.exports = function addVersionHeader(req, res, next) {
res.header("X-Valetudo-Version", version);
res.header("X-Valetudo-Commit-Id", commitId);
next();
};
3 changes: 3 additions & 0 deletions lib/webserver/middlewares/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
VersionMiddleware: require("./VersionMiddleware")
};

0 comments on commit d494510

Please sign in to comment.