diff --git a/config.conf b/config.conf index 8cb18a2b2..f155916ad 100644 --- a/config.conf +++ b/config.conf @@ -1,11 +1,13 @@ const port = 8000; const whitelist = ['127.0.0.1']; //Example for add several IP in whitelist: ['127.0.0.1', '192.168.0.10'] -const whitelistMode = true; //Disabling enabling the ip whitelist mode. true/false +const whitelistMode = false; //Disabling enabling the ip whitelist mode. true/false +const basicAuthMode = false; //Toggle basic authentication for endpoints. +const basicAuthUser = {username: "user", password: "password"}; //Login credentials when basicAuthMode is true. const autorun = true; //Autorun in the browser. true/false const enableExtensions = true; //Enables support for TavernAI-extras project const listen = true; // If true, Can be access from other device or PC. otherwise can be access only from hosting machine. module.exports = { - port, whitelist, whitelistMode, autorun, enableExtensions, listen + port, whitelist, whitelistMode, basicAuthMode, basicAuthUser, autorun, enableExtensions, listen }; diff --git a/server.js b/server.js index c7fd4a199..afb5a89cf 100644 --- a/server.js +++ b/server.js @@ -35,6 +35,7 @@ const rimraf = require("rimraf"); const multer = require("multer"); const http = require("http"); const https = require('https'); +const basicAuthMiddleware = require('./src/middleware/basicAuthMiddleware'); //const PNG = require('pngjs').PNG; const extract = require('png-chunks-extract'); const encode = require('png-chunks-encode'); @@ -194,6 +195,8 @@ const CORS = cors({ app.use(CORS); +if (listen && config.basicAuthMode) app.use(basicAuthMiddleware); + app.use(function (req, res, next) { //Security let clientIp = req.connection.remoteAddress; let ip = ipaddr.parse(clientIp);