Add option to start server with basic authentication enabled

This commit is contained in:
maver
2023-04-23 18:10:44 +02:00
parent 4da104211b
commit c821b1fba4
2 changed files with 7 additions and 2 deletions

View File

@ -1,11 +1,13 @@
const port = 8000; 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 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 autorun = true; //Autorun in the browser. true/false
const enableExtensions = true; //Enables support for TavernAI-extras project 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. const listen = true; // If true, Can be access from other device or PC. otherwise can be access only from hosting machine.
module.exports = { module.exports = {
port, whitelist, whitelistMode, autorun, enableExtensions, listen port, whitelist, whitelistMode, basicAuthMode, basicAuthUser, autorun, enableExtensions, listen
}; };

View File

@ -35,6 +35,7 @@ const rimraf = require("rimraf");
const multer = require("multer"); const multer = require("multer");
const http = require("http"); const http = require("http");
const https = require('https'); const https = require('https');
const basicAuthMiddleware = require('./src/middleware/basicAuthMiddleware');
//const PNG = require('pngjs').PNG; //const PNG = require('pngjs').PNG;
const extract = require('png-chunks-extract'); const extract = require('png-chunks-extract');
const encode = require('png-chunks-encode'); const encode = require('png-chunks-encode');
@ -194,6 +195,8 @@ const CORS = cors({
app.use(CORS); app.use(CORS);
if (listen && config.basicAuthMode) app.use(basicAuthMiddleware);
app.use(function (req, res, next) { //Security app.use(function (req, res, next) { //Security
let clientIp = req.connection.remoteAddress; let clientIp = req.connection.remoteAddress;
let ip = ipaddr.parse(clientIp); let ip = ipaddr.parse(clientIp);