mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Allow the app being served via SSL
This commit is contained in:
56
server.js
56
server.js
@@ -1,3 +1,21 @@
|
|||||||
|
const yargs = require('yargs/yargs');
|
||||||
|
const { hideBin } = require('yargs/helpers');
|
||||||
|
|
||||||
|
const cliArguments = yargs(hideBin(process.argv))
|
||||||
|
.option('ssl', {
|
||||||
|
type: 'boolean',
|
||||||
|
default: 'false',
|
||||||
|
describe: 'Enables SSL'
|
||||||
|
}).option('certPath', {
|
||||||
|
type: 'string',
|
||||||
|
default: 'certs/cert.pem',
|
||||||
|
describe: 'Path to your certificate file.'
|
||||||
|
}).option('keyPath', {
|
||||||
|
type: 'string',
|
||||||
|
default: 'certs/privkey.pem',
|
||||||
|
describe: 'Path to your private key file.'
|
||||||
|
}).argv;
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const compression = require('compression');
|
const compression = require('compression');
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -9,6 +27,7 @@ const open = require('open');
|
|||||||
|
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const multer = require("multer");
|
const multer = require("multer");
|
||||||
|
const http = require("http");
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
//const PNG = require('pngjs').PNG;
|
//const PNG = require('pngjs').PNG;
|
||||||
const extract = require('png-chunks-extract');
|
const extract = require('png-chunks-extract');
|
||||||
@@ -43,7 +62,7 @@ if (fs.existsSync(whitelistPath)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const whitelistMode = config.whitelistMode;
|
const whitelistMode = config.whitelistMode;
|
||||||
const autorun = config.autorun;
|
const autorun = config.autorun && !cliArguments.ssl;
|
||||||
const enableExtensions = config.enableExtensions;
|
const enableExtensions = config.enableExtensions;
|
||||||
const listen = config.listen;
|
const listen = config.listen;
|
||||||
|
|
||||||
@@ -2319,23 +2338,44 @@ function getAsync(url, args) {
|
|||||||
}
|
}
|
||||||
// ** END **
|
// ** END **
|
||||||
|
|
||||||
app.listen(server_port, (listen ? '0.0.0.0' : '127.0.0.1'), async function () {
|
const tavernUrl = new URL(
|
||||||
|
(cliArguments.ssl ? 'https://' : 'http://') +
|
||||||
|
(listen ? '0.0.0.0' : '127.0.0.1') +
|
||||||
|
(':' + server_port)
|
||||||
|
);
|
||||||
|
|
||||||
|
const setupTasks = async function () {
|
||||||
ensurePublicDirectoriesExist();
|
ensurePublicDirectoriesExist();
|
||||||
await ensureThumbnailCache();
|
await ensureThumbnailCache();
|
||||||
|
|
||||||
// Colab users could run the embedded tool
|
// Colab users could run the embedded tool
|
||||||
if (!is_colab) {
|
if (!is_colab) await convertWebp();
|
||||||
await convertWebp();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Launching...');
|
console.log('Launching...');
|
||||||
if (autorun) open('http://127.0.0.1:' + server_port);
|
if (autorun) open(tavernUrl);
|
||||||
console.log('TavernAI started: http://127.0.0.1:' + server_port);
|
console.log('TavernAI started: ' + tavernUrl);
|
||||||
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
||||||
convertStage1();
|
convertStage1();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
if (true === cliArguments.ssl)
|
||||||
|
https.createServer(
|
||||||
|
{
|
||||||
|
cert: fs.readFileSync(cliArguments.certPath),
|
||||||
|
key: fs.readFileSync(cliArguments.keyPath)
|
||||||
|
}, app)
|
||||||
|
.listen(
|
||||||
|
tavernUrl.port,
|
||||||
|
tavernUrl.hostname,
|
||||||
|
setupTasks
|
||||||
|
);
|
||||||
|
else
|
||||||
|
http.createServer(app).listen(
|
||||||
|
tavernUrl.port,
|
||||||
|
tavernUrl.hostname,
|
||||||
|
setupTasks
|
||||||
|
);
|
||||||
|
|
||||||
//#####################CONVERTING IN NEW FORMAT########################
|
//#####################CONVERTING IN NEW FORMAT########################
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user