Allow the app being served via SSL

This commit is contained in:
maver
2023-04-22 19:46:30 +02:00
parent e19990ee45
commit ea1da47c99

View File

@@ -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 compression = require('compression');
const app = express();
@@ -9,6 +27,7 @@ const open = require('open');
const rimraf = require("rimraf");
const multer = require("multer");
const http = require("http");
const https = require('https');
//const PNG = require('pngjs').PNG;
const extract = require('png-chunks-extract');
@@ -43,7 +62,7 @@ if (fs.existsSync(whitelistPath)) {
}
const whitelistMode = config.whitelistMode;
const autorun = config.autorun;
const autorun = config.autorun && !cliArguments.ssl;
const enableExtensions = config.enableExtensions;
const listen = config.listen;
@@ -2319,23 +2338,44 @@ function getAsync(url, args) {
}
// ** 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();
await ensureThumbnailCache();
// Colab users could run the embedded tool
if (!is_colab) {
await convertWebp();
}
if (!is_colab) await convertWebp();
console.log('Launching...');
if (autorun) open('http://127.0.0.1:' + server_port);
console.log('TavernAI started: http://127.0.0.1:' + server_port);
if (autorun) open(tavernUrl);
console.log('TavernAI started: ' + tavernUrl);
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
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########################