Merge pull request #1066 from bdashore3/staging
Allow additional headers to be passed to local backends
This commit is contained in:
commit
83ff2e6edc
|
@ -15,17 +15,21 @@ const skipContentCheck = false; // If true, no new default content will be deliv
|
||||||
// Change this setting only on "trusted networks". Do not change this value unless you are aware of the issues that can arise from changing this setting and configuring a insecure setting.
|
// Change this setting only on "trusted networks". Do not change this value unless you are aware of the issues that can arise from changing this setting and configuring a insecure setting.
|
||||||
const securityOverride = false;
|
const securityOverride = false;
|
||||||
|
|
||||||
|
// Request overrides for additional headers
|
||||||
|
const requestOverrides = [];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
port,
|
port,
|
||||||
whitelist,
|
whitelist,
|
||||||
whitelistMode,
|
whitelistMode,
|
||||||
basicAuthMode,
|
basicAuthMode,
|
||||||
basicAuthUser,
|
basicAuthUser,
|
||||||
autorun,
|
autorun,
|
||||||
enableExtensions,
|
enableExtensions,
|
||||||
listen,
|
listen,
|
||||||
disableThumbnails,
|
disableThumbnails,
|
||||||
allowKeysExposure,
|
allowKeysExposure,
|
||||||
securityOverride,
|
securityOverride,
|
||||||
skipContentCheck,
|
skipContentCheck,
|
||||||
|
requestOverrides,
|
||||||
};
|
};
|
||||||
|
|
29
server.js
29
server.js
|
@ -185,7 +185,14 @@ function get_mancer_headers() {
|
||||||
return api_key_mancer ? { "X-API-KEY": api_key_mancer } : {};
|
return api_key_mancer ? { "X-API-KEY": api_key_mancer } : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOverrideHeaders(urlHost) {
|
||||||
|
const overrideHeaders = config.requestOverrides?.find((e) => e.hosts?.includes(urlHost))?.headers;
|
||||||
|
if (overrideHeaders && urlHost) {
|
||||||
|
return overrideHeaders;
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
|
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
|
||||||
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
|
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
|
||||||
|
@ -540,7 +547,10 @@ app.post("/generate", jsonParser, async function (request, response_generate) {
|
||||||
console.log(this_settings);
|
console.log(this_settings);
|
||||||
const args = {
|
const args = {
|
||||||
body: JSON.stringify(this_settings),
|
body: JSON.stringify(this_settings),
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: Object.assign(
|
||||||
|
{ "Content-Type": "application/json" },
|
||||||
|
getOverrideHeaders((new URL(api_server))?.host)
|
||||||
|
),
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -630,11 +640,19 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||||
});
|
});
|
||||||
|
|
||||||
async function* readWebsocket() {
|
async function* readWebsocket() {
|
||||||
|
const streamingUrlString = request.header('X-Streaming-URL').replace("localhost", "127.0.0.1");
|
||||||
|
const streamingUrl = new URL(streamingUrlString);
|
||||||
const websocket = new WebSocket(streamingUrl);
|
const websocket = new WebSocket(streamingUrl);
|
||||||
|
|
||||||
websocket.on('open', async function () {
|
websocket.on('open', async function () {
|
||||||
console.log('WebSocket opened');
|
console.log('WebSocket opened');
|
||||||
const combined_args = Object.assign(request.body.use_mancer ? get_mancer_headers() : {}, request.body);
|
const combined_args = Object.assign(
|
||||||
|
{},
|
||||||
|
request.body.use_mancer ? get_mancer_headers() : getOverrideHeaders(streamingUrl?.host),
|
||||||
|
request.body
|
||||||
|
);
|
||||||
|
console.log(combined_args);
|
||||||
|
|
||||||
websocket.send(JSON.stringify(combined_args));
|
websocket.send(JSON.stringify(combined_args));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -716,6 +734,8 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||||
|
|
||||||
if (request.body.use_mancer) {
|
if (request.body.use_mancer) {
|
||||||
args.headers = Object.assign(args.headers, get_mancer_headers());
|
args.headers = Object.assign(args.headers, get_mancer_headers());
|
||||||
|
} else {
|
||||||
|
args.headers = Object.assign(args.headers, getOverrideHeaders((new URL(api_server))?.host));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -783,6 +803,7 @@ app.post("/getchat", jsonParser, function (request, response) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Only called for kobold and ooba/mancer
|
||||||
app.post("/getstatus", jsonParser, async function (request, response) {
|
app.post("/getstatus", jsonParser, async function (request, response) {
|
||||||
if (!request.body) return response.sendStatus(400);
|
if (!request.body) return response.sendStatus(400);
|
||||||
api_server = request.body.api_server;
|
api_server = request.body.api_server;
|
||||||
|
@ -797,6 +818,8 @@ app.post("/getstatus", jsonParser, async function (request, response) {
|
||||||
|
|
||||||
if (main_api == 'textgenerationwebui' && request.body.use_mancer) {
|
if (main_api == 'textgenerationwebui' && request.body.use_mancer) {
|
||||||
args.headers = Object.assign(args.headers, get_mancer_headers());
|
args.headers = Object.assign(args.headers, get_mancer_headers());
|
||||||
|
} else {
|
||||||
|
args.headers = Object.assign(args.headers, getOverrideHeaders((new URL(api_server))?.host));
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = api_server + "/v1/model";
|
const url = api_server + "/v1/model";
|
||||||
|
|
Loading…
Reference in New Issue